Custom event handlers and searching a listview

  • Thread starter Thread starter Simon Middlemiss
  • Start date Start date
S

Simon Middlemiss

I am writting a program to manage DTS packages which is based on the code
example at the following link
http:\\www.support.microsoft.com/?kbid=319985.

I need to do things in a Windows Forms Application when various things occur
in the package so I have written some custom events to reraise the events
caught in the PackageEventsSink class.

I also have a listview in details mode with several columns, my problem is
that when I try and iterate through the listbox items when inside the event
handler for the StartPackage event the application hangs. Also when I do a
quickview on the listbox, when I expand the items object if I scroll down
through the list it hangs when I get to "expectingMouseUp", which is set to
false.

I have no idea what could be causing this, and it is *really* annoying
becuase the program is almost finished!

I hope someone can help

Cheers

Simon
 
Hi Simon,

Does your "eventhandler for the StartPackage event" mean OnStart method of
DTS.PackageEvents?
What is your "expectingMouseUp"?
Normally, the WinForm UI hang is caused by the long-time IO operation in
the main thread, which blocks the refresh of the UI.
I think you should check in your code which manipulates the UI, do not do
synchronization operation with UI.
Also, you can invoke Invalidate method of the control to force it refresh.
I think a better design is manipulate the data operation in a seperate
worker thread, then use control.invoke or control.BeginInvoke.
The articles below talks about the design-pattern of mainpulate WinForm UI
in multiThread:
http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/default.aspx

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Jeffrey,

Thanks for your reply. I have upload my code to
www.oursadlives.com\dts\ManagedDTS.cs and
www.oursadlives.com\dts\DeployToolDlg.cs. The important UI methods are
"PrepPackage()", "RunPackage()" and "PackageStarted(object sender,
PackageEventsSink.PackageEventArgs e)"

The PackageEventsSink.OnStart method raises a custom event OnPackageStart
which I have hooked into in the dialog class. It is in the handler for the
OnPackageStart event where I am having problems (everything works fine if I
don't try and do stuff with the listview as I output stuff to the console to
tell me what's going on) if I try and step through the code it never gets
into the loop it hangs on the foreach(...) statement. As for
expectingMouseUp, as far as I know this is just a property of
ListView.Items, all I have been able to verify is that if I expand Items in
watch, then I can scoll up and down fine unless I let
ListView.Items.expectingMouseUp appear in which case it causes Visual Studio
to hang until I kill the running app through taskmanager.

I have tried executing the DTS class in another thread and that doesn't
change anything. Also I have noticed that if I am looping through the
listview then I receive no more console messages after the OnStart call.

I have read the document that you posted a link to, perhaps I haven't
totally understood it yet but surely I can't do the work on the listview in
a separate thread becuase it was created on the UI thread?

I hope this better explains my situation.

Cheers

Simon
 
Hi Simon,

Thanks for your feedback.
I found your problem strange. As you said, your application hangs at
"foreach(ListViewItem item in TasksListView.Items)", I think this statement
should work fine.
I think you should set a break point before this statement and in the
PackageStarted method, then in the debugger "watch window" watch if
TasksListView.Items collection is the correct value. Also, you can try to
invoke PackageStarted method in another method(such as button's click
event), if the problem still arise.
For the "expectingMouseUp", I have found it in debugger "watch window", I
think it is an internal field for .Net, I do now know why you care about
this field. Acutally, there is no document for the usage of this field.
For multiThreading modal, the listview is created in Main UI thread, but
you can expose a public method for the operation of listview, then in your
worker thread, you can use Control.BeginInvoke to execute this method from
worker thread. The method's execute is asynchronized.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Comments embedded below...
Thanks for your feedback.
I found your problem strange. As you said, your application hangs at
"foreach(ListViewItem item in TasksListView.Items)", I think this statement
should work fine.
Good!

I think you should set a break point before this statement and in the
PackageStarted method, then in the debugger "watch window" watch if
TasksListView.Items collection is the correct value. Also, you can try to
invoke PackageStarted method in another method(such as button's click
event), if the problem still arise.

I'll try that
For the "expectingMouseUp", I have found it in debugger "watch window", I
think it is an internal field for .Net, I do now know why you care about
this field. Acutally, there is no document for the usage of this field.

I do not care about in the slightest I mentioned it only becuase it seemed
that Visual Studio crashed only when you try to and scroll past that field
in the debugger "watch window"
For multiThreading modal, the listview is created in Main UI thread, but
you can expose a public method for the operation of listview, then in your
worker thread, you can use Control.BeginInvoke to execute this method from
worker thread. The method's execute is asynchronized.

I'll do this and get back to you

Cheers Simon
 
Hi Simon,

If you have any further question, feel free to tell me, I will work with
you.
For "expectingMouseUp" in watch window, in my VS.net IDE, I can watch this
field, and its value is false, but when I view and scroll pass that value,
nothing special happens and the IDE will not crash.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top