idoprz

Hi.

I have a window that opens after i click on a button. The new window takes some time to start because it should get some information from a web service. I start the new window on a thread so that it will not freeze my main window.

I want to change the mouse cursor or create a progress bar. My problem is how can i know when the window that opened is ready - so I can stop the progress bar (or change back the cursor).

So, what should I do Create some kind of event handlers or something like that

Thank you




Re: Windows Communication Foundation (Indigo) comunicating with two windows

OmegaMan

Note you only want to do GUI operations on the main thread otherwise you will get drawing lockups. I recommend that you put the web services processing on a different thread but keep both windows processing on the primary.

To signal between the threads, have the web service thread invoke back to the main thread that it is finished and fill the second window with data. Check out this article on Threading in Windows Forms.





Re: Windows Communication Foundation (Indigo) comunicating with two windows

JDPeckham

Two windows can be on the same thread without locking eachother up if you use Show() instead of ShowDialog() so the first thing i would do is ditch the needless extra thread. Now what's probably locking up your UI is that you're calling your webservice synchronously (on the same thread), probably in the constructor or the Load event in your second form, right

If this is the case, what you want to do is call your web service asynchronously in your FIRST form, and the callback will get the data, and create your second form. Because why would we want that second form taking up memory until the data is ready anyhow.

If i could give you assigned reading on this, i'd say you need to check out:

http://msdn2.microsoft.com/en-us/library/ms228969.aspx

http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

http://msdn2.microsoft.com/en-us/library/system.delegate.aspx

http://msdn2.microsoft.com/en-us/library/system.asynccallback.aspx

http://msdn2.microsoft.com/en-us/library/system.iasyncresult.aspx

and

http://msdn2.microsoft.com/en-us/library/aa480512.aspx

Some explanation: Creating extra threads without using the threadpool or async is dangerous because if every programmer on a project did that then you'd never be able to keep concurrency because you wouldn't know when or where or how many threads are out there. Even if you're the only programmer on a project, you can't possibly keep track of when your Threads are exiting and such, thats why async is so much better because you can get a iasyncresult and that is your gateway to status about your extra thread at any time.

hope i've helped,

J






Re: Windows Communication Foundation (Indigo) comunicating with two windows

idoprz

actually, it's not an ordinary web service, it is WCF service, so i'm not sure how can i call this asynchronously. But I'll try some of the suggestions there.






Re: Windows Communication Foundation (Indigo) comunicating with two windows

OmegaMan

idoprz wrote:

actually, it's not an ordinary web service, it is WCF service, so i'm not sure how can i call this asynchronously. But I'll try some of the suggestions there.



If you are not speaking to my post, please ignore ... regardless of what is being done on the ports, all such code needs to not write directly to the interface.





Re: Windows Communication Foundation (Indigo) comunicating with two windows

timvw

Even if the proxy to the WCF service doesn't have async (begin-/endinvoke) possibility (i would find that odd, but i don't know enough about WCF to say that for sure) you could simply create a delegate that has the signature of the method you're going to call.. And
via that delegate you get async functionality quite easily...

All you would need to do is pass in a delegate to the function that will perform code when the call has completed...

An example: http://www.timvw.be/performing-long-running-tasks-in-a-windows-application/





Re: Windows Communication Foundation (Indigo) comunicating with two windows

Brian McNamara - MSFT

If you want to call a WCF service async, you can generate an async client using svcutil.exe with the /async switch.

See also http://blogs.msdn.com/mjm/archive/2005/05/04/414793.aspx (sync versus async is a local thing).