Form partially disappers during long processing in a different thread

  • Thread starter Thread starter TomTom
  • Start date Start date
T

TomTom

In my C# WinForm program, I create a new thread to do a long process of
inserting data from Access files to SQL DB. The problem is that some parts
of the MainForm pertially disappear while the new thread is doing its task.
I found many articles on this on the Internet and followed the example from
http://www.codeproject.com/csharp/workerthread.asp. Still some parts of the
MainForm (buttons) disappear and it appears that the code is not updating
the label on the MainForm properly. Are there any areas that I might be
overlooking?

The code looks like this, although this partial code may not make much
sense..

mainForm.BeginInvoke(mainForm.delegateUpdateMainUi, new Object[] {"Number of
records inserted: " + numberOfRecordsProcessed.ToString()} );

Thanks,
TomTom
 
Hi,

Are you updating the UI frmo the worker thread?
If so use Control.Invoke ( do a search in the archives by Control.Invoke )
and you will find a lot of code snipets that works.

IF you create a new thread the UI should work fine, unless you are
interacting with the UI frmo the worker thread.

Cheers,
 
Thanks for your answer, Ignacio.
I was using the Join() method and after I removed this, the form began to
behave as expected.

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Are you updating the UI frmo the worker thread?
If so use Control.Invoke ( do a search in the archives by Control.Invoke )
and you will find a lot of code snipets that works.

IF you create a new thread the UI should work fine, unless you are
interacting with the UI frmo the worker thread.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


TomTom said:
In my C# WinForm program, I create a new thread to do a long process of
inserting data from Access files to SQL DB. The problem is that some
parts of the MainForm pertially disappear while the new thread is doing
its task. I found many articles on this on the Internet and followed the
example from http://www.codeproject.com/csharp/workerthread.asp. Still
some parts of the MainForm (buttons) disappear and it appears that the
code is not updating the label on the MainForm properly. Are there any
areas that I might be overlooking?

The code looks like this, although this partial code may not make much
sense..

mainForm.BeginInvoke(mainForm.delegateUpdateMainUi, new Object[] {"Number
of records inserted: " + numberOfRecordsProcessed.ToString()} );

Thanks,
TomTom
 
Back
Top