none
Invoke with DataSet.Merge sometimes freezes main thread. RRS feed

  • Question

  • I've got a program with a list that displays data in a DataSet.
    The data is periodically updated in a backgroundworker that is continuously running.
    When the background thread has fetched the updated data it sends it to the main thread so that it can update it's DataSet (to avoid cross thread crap).
    I do this with

     

    form.Invoke((MethodInvoker)delegate { dataSet.Merge(tmpDataSet); });
    

     


    The problem is that sometimes, very rarely, like once in 24 hours if I update every 20 seconds I get the main thread to freeze permanently.
    Well, it's not completely frozen since I've got a keyboard hook that seems to be called. But it doesn't seem to be processing paint messages or something.
    I tried with BeginInvoke, but that changed nothing.
    Is the tmpDataSet locked and if so, who isn't it always locked?
    How do I debug it more thoroughly when the main thread is just in Application.Run();

    Monday, December 5, 2011 5:12 PM

Answers

All replies

  • Hi,

    Welcome to the MSDN forum.

    Could you please provide more code snippet of how you start the background thread and how you invoke a method in UI thread?

    We need more code snippet to reproduce this issue. Any more information is appreciated.

    Thanks.

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 6, 2011 9:02 AM
  • May be due to huge number of records in the database, which is taking more than 20 seconds to merge the records and before first merge finishes, another merge request comes which is causing your application to freeze ( Just a wild guess). Try increasing the duration from 20 seconds to some greater number.
    Please mark this post as answer if it solved your problem. Happy Programming!
    Tuesday, December 6, 2011 12:11 PM
  • The invoke is in the first post.
    I create the worker thread like this

                updateDataSetBackgroundWorker = new BackgroundWorker();
                updateDataSetBackgroundWorker.DoWork += updateDataSetBackgroundWorker_DoWork;
                updateDataSetBackgroundWorker.RunWorkerAsync();

            private void updateDataSetBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
            {
                LastUpdated = DateTime.Now;

                while(true)
                {
                    Thread.Sleep(1000);

                    if(Cancel)
                        break;

                    // Do it this way instead of sleeping entire interval, so that you can force an update of the list
                    if(DateTime.Now.Subtract(LastUpdated) > new TimeSpan(0, 0, updateInterval))
                        UpdateDataSet = true;

                    if(!UpdateDataSet)
                        continue;

                    try
                    {
                        SubscriberAndAccountInfo.UpdateInfo(Imsi);
                    }
                    catch(ObjectDisposedException)
                    {
                    }
                }
            }

    The UpdateInfo is bit too big to post, it fetches data for and invokes like I discribed.

    Tuesday, December 6, 2011 12:18 PM
  • Why would two invokes make the main thread stop painting?

    Will not the invokes just be queued?

    Tuesday, December 6, 2011 12:20 PM
  • And yes, I'm pretty sure this is the cause of the main thread stop painting, since I've disable that thread and I've had three programs running for five days without it happening.
    Tuesday, December 6, 2011 12:22 PM
  • What is 'Imsi' that you are sending to UpdateInfo function? does it get modified while the backgroundworker is running?
    Please mark this post as answer if it solved your problem. Happy Programming!
    Tuesday, December 6, 2011 1:08 PM
  • It's a list of ids.
    It's not modified.
    Tuesday, December 6, 2011 2:25 PM
  • Have you tried extended interval time?

    If it is caused by that interval time is too short, just extend it.

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, December 7, 2011 8:30 AM
  • Why would the time between updates matter. These merges are pretty instant.
    Wednesday, December 7, 2011 8:32 AM
  • I'm now getting indications that the freeze of the invoke might be just a symptom of an unrelated freeze in the main thread, not the cause. Will check that out first.
    Wednesday, December 7, 2011 8:52 AM
  • You can use WinDbg + SOS to debug such issue. use ADPlus to capture a dump file. 

     

    ADPlus is shipped with Debugging Tools For Windows which available at here, you can try this command to capture a dump file:

     

    adplus -crash -o d:\dumps -pn MyApplication

     

    You can see the call stack, so we can know where it stops and freezes.

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, December 8, 2011 7:59 AM
  • I've disabled the invoke completely and it still freezes. So the blocked invoke was just a symptom.

    I've got a debug built applications frozen now, so I've attached the debugger.
    The main thread is in Application.Run(), which makes me think it's a bug in DevExpress (which is the GUI toolkit I'm using). The problem is proving that. =)

    Thursday, December 8, 2011 8:50 AM
  • So you can try to run it on other machines.

    If it is a issue of GUI toolkit, it will run smoothly on other machines.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 9, 2011 6:09 AM
  • I'm running it on several machines.
    Friday, December 9, 2011 9:02 AM
  • You can submit your suggestions to Microsoft Connect feedback portal http://connect.microsoft.com, Microsoft engineers will evaluate them seriously, thanks. 

    If this issue is urgent, please contact support at http://support.microsoft.com


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 9, 2011 9:08 AM
  • Moreover, it is the DevExpress homesite for you:

    http://www.devexpress.com/

    You can contact with the support team of the production.

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 13, 2011 6:56 AM
  • Tuesday, December 13, 2011 8:31 AM