none
The invoke method not work in the windows forms application and the form freezes when the windows was locked. RRS feed

  • 常规讨论

  • In my windows forms application, the UI thread created a new thread to process the data. when the data thread processed some data and return the message to the UI used "Control.Invoke" method. It is work normally. But when the application was running and the windows was locked and then uplocked, the forms application is freezes. I debugged and found that the application wait for ever at Invoke method when the windows was locked.
    How can I resolve this problem? Thank you.
    2009年7月2日 8:21

全部回复

  • Hi,
       How about try to use multiple-threads ?  
    Frank.Xu Lei--谦卑若愚,好学若饥
    专注于.NET平台下分布式应用系统开发和企业应用系统集成
    Focus on Distributed Applications Development and EAI based on .NET
    老徐的博客:http://frank_xl.cnblogs.com
    2009年7月2日 10:25
    版主
  • I'm using multiple-threads.

    2009年7月3日 3:22
  • there is a method in the form, it will run when click a button.
     
      public void PerformProcess()
      {

    MAPIExport export = new MAPIExport();
    export.PSTFileObjects = PSTList;
    export.MessageProcessed += export_MessageProcessed;
    ......

       Thread exportThread = new Thread(export.Export);
       exportThread.IsBackground = true;
       exportThread.Start();
      }


    In the Export method will run a UpdateUI method:
            private void UpdateUI(int MsgCnt, int ErrCnt)
            {
    ......
    ......
    ......
                this.MessageProcessed(string.Empty, string.Empty, CurrMsgCnt, CurrErrCnt, _MessageTotal, _ErrorTotal);
            }


      private void export_MessageProcessed(string Store, string Path, int Count, int ErrorCount, int MessageTotal, int ErrorTotal)
      {
                if (View.InvokeRequired)
                {
                    View.Invoke(new MAPIExport.MAPIMessageProcessed_EventHandler(export_MessageProcessed), new object[] {Store, Path, Count, ErrorCount, MessageTotal, ErrorTotal});
                } 
                else
                {
                    View.UpdateMessageCount(Store, Path, Count, ErrorCount, MessageTotal, ErrorTotal);
                }
      }


    When the windows locked and uplocked, the application will halt at the "View.Invoke(......)".

    2009年7月3日 3:31
  • I changed my code to used a timer instead Invoke method.
    It can keep running but the UI can't be operate when the windows locked and uplocked.
    When the process finished, the UI was resume.

    2009年7月3日 3:37
  • Hello,

    Could you clarify your scenario?

    1. Why do you say that the application hangs because Windows is locked and unlocked in your scenario? Whether you mean that Windows OS is locked and unlocked in this scenario.

    2. How many threads does your application create to execute the task in this scenario?

    3. Based on your post, the application will halt at Control.Invoke method. My recommendation is that you need to add one breakpoint to step into that subroutine to check where the application is waiting for some locked resources in this scenario. I would guess whether your application starts two or more threads so that a race condition or deadlock occurs.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    2009年7月6日 6:51
    版主
  • We are changing the issue type to “General Discussion” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by changing the type at the top of the post window. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions. Thank you!
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    2009年7月8日 7:03
    版主