Threading problem

G

Guest

Hello, hopefully I can describe this probably correctly.

I have what I thought was a simply form that opens a popup (another form)
whenever an event happens. My main form, Form A, has an instance of Form B
created on it. I set a bunch of parameters and then call a method on Form B
to show itself and do a few more things. I can get the event to fire correct
by pressing a button; everything was working great.

However, I'm now trying to add in a class file that will check an XML stream
over and over. If that xml file changes, I need the popup from above to open
up to alert the user that something has changed. I fire off a thread, but of
course I can't open the popup from the thread due to the cross-thread error.

So basically, I have Form A (the main form), which calls Form B to open
(Form A also sets some parameters on the 2nd form). I wish to access the
instance of Form B that is running on Form A from Class C. I've looked in to
delegates and invoking, but I guess I'm just totally lost about what goes
where. I've also tried creating a worker class and just open up Form B
directly from Class C, but that doesn't work very well and it's not the ideal
solution anyway.

Any tips? I've googled quite a bit, but I'm still scratching my head.

Frij
 
G

Guest

Figures that right after posting this, I would get it working correctly. :) I
ended up calling invoke on the main form, which seems to be working exactly
as I need it to.
 
G

Guest

You should use a filesystemwatcher to raise an event when the file changes.
This is windows notifying you when the file is written. It saves having to
read the file over and over and raises the event on the UI thread so no need
to Invoke.

Ciaran O'Donnell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top