Form partially disappers during long processing in a different thread

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TomTom

    Form partially disappers during long processing in a different thread

    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.BeginI nvoke(mainForm. delegateUpdateM ainUi, new Object[] {"Number of
    records inserted: " + numberOfRecords Processed.ToStr ing()} );

    Thanks,
    TomTom


  • Ignacio Machin \( .NET/ C#  MVP \)

    #2
    Re: Form partially disappers during long processing in a different thread

    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" <no_spam@nospam fordiscussion.c om> wrote in message
    news:uCWTxI89EH A.2180@TK2MSFTN GP10.phx.gbl...[color=blue]
    > 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.BeginI nvoke(mainForm. delegateUpdateM ainUi, new Object[] {"Number
    > of records inserted: " + numberOfRecords Processed.ToStr ing()} );
    >
    > Thanks,
    > TomTom
    >
    >[/color]


    Comment

    • TomTom

      #3
      Re: Form partially disappers during long processing in a different thread

      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 )" <ignacio.mach in AT dot.state.fl.us > wrote
      in message news:%23TuBUS$9 EHA.1260@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > 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" <no_spam@nospam fordiscussion.c om> wrote in message
      > news:uCWTxI89EH A.2180@TK2MSFTN GP10.phx.gbl...[color=green]
      >> 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.BeginI nvoke(mainForm. delegateUpdateM ainUi, new Object[] {"Number
      >> of records inserted: " + numberOfRecords Processed.ToStr ing()} );
      >>
      >> Thanks,
      >> TomTom
      >>
      >>[/color]
      >
      >[/color]


      Comment

      Working...