Skip to Content
0
Apr 17, 2012 at 07:51 AM

How to ignore "Object reference not set" with OnMouseMove?

40 Views

I know that there are other threads for this problem (Frustrating Error - Please Help). But I have this error and need to make my application running.

I found where exceptions occurs in my code and I would like to suppress it. I use:

Catch ex As NullReferenceException When ex.TargetSite.Name = "OnMouseMove" And ex.TargetSite.ReflectedType.FullName = "CrystalDecisions.Windows.Forms.PageControl"

Is it specific enough? Is it safe?

Full code is (wpf DoEvents see http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.pushframe.aspx ):

Public Shared Sub DoEvents()

Dim frame As New DispatcherFrame()

Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, New DispatcherOperationCallback(AddressOf ExitFrame), frame)

Try

Dispatcher.PushFrame(frame)

Catch ex As NullReferenceException When ex.TargetSite.Name = "OnMouseMove" And ex.TargetSite.ReflectedType.FullName = "CrystalDecisions.Windows.Forms.PageControl"

End Try

End Sub

Public Shared Function ExitFrame(ByVal f As Object) As Object

CType(f, DispatcherFrame).Continue = False

Return Nothing

End Function