Re: Invoking a form that was created on a separate thread
- From: "Daniel Moth" <dmoth74@xxxxxxxxxxx>
- Date: Fri, 15 Apr 2005 20:53:53 +0100
Check out the BackgroundWorker or do it yourself (parsing on thread and updating the form with control invoke)
Cheers Daniel -- http://www.danielmoth.com/Blog/
"Dannyboy" <daniel@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:%23bFkZNfQFHA.248@xxxxxxxxxxxxxxxxxxxxxxx
Hi Chris your right its not good all, the the thing is the xml files that are being parsed are pretty big and they take quite a bit of time, so I need to put a progress bar on, I did try creating that on the main the and then updating that from a separate thread.
If there is a better way to do this I'm open to all suggestions cos this is p#@*ing me off
Thanks
Dan
"Chris Tacke, eMVP" <ctacke@xxxxxxxxxxxxxxxxxxxxxx> wrote in message news:u9%23zJ0dQFHA.1528@xxxxxxxxxxxxxxxxxxxxxxxThe first question has to be why are you creating a Form on another thread? It's a very bad idea, a bad design, and bad practice.
-- Chris Tacke Co-founder OpenNETCF.org Has OpenNETCF helped you? Consider donating to support us! http://www.opennetcf.org/donate
"Dan" <daniel@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:e5x$vrdQFHA.3628@xxxxxxxxxxxxxxxxxxxxxxxHi everyone
I have a class which parses an xml file and creates a form and its controls from it, and I have recenlty moved this so that it happens on its own thread, I know about controls that are created on a different thread to the UI can not just have its methods called without using invoke so with this I have tried several different ways to get the form to show but I'm having problems.
The ways I have have tried are:
1. With the form that is returned from the parsing class I have tried
me.invoke(new delegateSub(addressof newform.show))
This throws the error "Cannot call Invoke or InvokeAsync on a control until the window handle has been created."
2. Add a controller class that is also created on the separate thread which shows the form when the parsing is complete, this does show the form briefly but it then disappears.
3. With the same controller class I use Application.Run(parsedform). This works beautifully apart from one small snag, the class which starts the parsing is passed a reference to the parser and acts as the code behind for the the controls that are created in the parsed form e.g. the click event of a button in the parsed form is handled by a method in the class that is sent to the parser. This is where this method seems to fall down because the reference no longer works.
Am I fighting a loosing battle with this or can anyone offer some code of wisdom.
Any help will be much appreciated.
Many Thanks Dan
.
- Follow-Ups:
- Re: Invoking a form that was created on a separate thread
- From: Dannyboy
- Re: Invoking a form that was created on a separate thread
- References:
- Invoking a form that was created on a separate thread
- From: Dan
- Re: Invoking a form that was created on a separate thread
- From: Chris Tacke, eMVP
- Re: Invoking a form that was created on a separate thread
- From: Dannyboy
- Invoking a form that was created on a separate thread
- Prev by Date: Re: How to Change device resolution to VGA?
- Next by Date: Re: CF 1.0 SP3 developer bits
- Previous by thread: Re: Invoking a form that was created on a separate thread
- Next by thread: Re: Invoking a form that was created on a separate thread
- Index(es):