none
Suggestions on getting around a blocking ActiveX control. RRS feed

  • Question

  • Hi,

    I have a 3rd party ActiveX control in my c# .net Windows Forms Application. They have provided an SDK which includes the control and the methods needed. However, the ActiveX control blocks during some of its methods. The control has a Connect() function which look for a client based on IP and port. Normally it works well, but I can not count on users to provide the correct connection properties. What I am struggling with is when the control can not find the client machine, my application UI is blocked until the control's function times out. This is about 30 seconds. Not bad, but it inhibits the Cursor being set to Wait and all UI functionality. So if I run the Connect function first thing the user sits waiting without feedback. If I wait until everything is running I can set a label, but again the UI(even moving the form) is blocked. I have tried all sorts of async/Task/await functions, but so far no matter where I put the connection function the UI gets blocked. Anyone have any suggestions? I am new to task so I may very well be over thinking or missing something.

     Thanks


    • Edited by mgppgm Friday, November 10, 2017 5:52 PM
    Friday, November 10, 2017 5:50 PM

Answers

  • Hello mgppgm,

    >>'Does anyone have any suggestions for offloading <a> com control's processing to another thread'

    For a control, it only accessed from the thread it was created on. The thread we named it as UI thread. You couldn't execute the Yourcontrol.connect method run another thread. It will throw "Cross-thread" exception. But if you has known the activex control source code, you could achieve it  by editing some code .

    For instance.

     private void button1_Click(object sender, EventArgs e)
            {
                int i = 0;
                while (true)
                {
                    Console.WriteLine(i++);
                    Thread.Sleep(500);
                }
            }

    For the above code, you couldn't execute button1.PerformClick from other thread.

    private void button1_Click(object sender, EventArgs e)
            {
                Test();
            }
            public void Test() {
                int i = 0;
                while (true)
                {
                    Console.WriteLine(i++);
                    Thread.Sleep(500);
                }
            }

    you could access test method rather than invoke button1.PerformClick from other thread. Of course it doesn't block the UI thread.

    Thread thread = new Thread(form6.Test);
    
      thread.Start();

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Fei HuModerator Monday, November 13, 2017 10:35 AM
    • Marked as answer by mgppgm Monday, November 13, 2017 2:22 PM
    Monday, November 13, 2017 10:35 AM
    Moderator

All replies

  • ActiveX is COM based. Doesn't the 3rd party vendor have a .NET solution?
    Saturday, November 11, 2017 3:01 AM
  • Evidently not. I had to register the ocx dlls. But then I was able to add them as a com object in the tool box. This company is proving to be unresponsive. I have asked their developers for information on the com objects and suggestions. But they must be too busy to answer. So I'm asking the forum on ideas to try as a work around.
    Saturday, November 11, 2017 4:55 PM
  • The forum doesn't support 3rd party solutions.
    Saturday, November 11, 2017 5:06 PM
  • Thank you, I know that. My question is, 'Does anyone have any suggestions for offloading <a> com control's processing to another thread'? I have tried task, task.run and various mixes including awaits, but my knowledge and experience is lacking. I am not asking anyone to support the control, just for their ideas based on similar experiences. Even when I 'Invoke' the controls method the UI is blocked until it connects or times out. 
    Saturday, November 11, 2017 6:05 PM
  • Hello mgppgm,

    >>'Does anyone have any suggestions for offloading <a> com control's processing to another thread'

    For a control, it only accessed from the thread it was created on. The thread we named it as UI thread. You couldn't execute the Yourcontrol.connect method run another thread. It will throw "Cross-thread" exception. But if you has known the activex control source code, you could achieve it  by editing some code .

    For instance.

     private void button1_Click(object sender, EventArgs e)
            {
                int i = 0;
                while (true)
                {
                    Console.WriteLine(i++);
                    Thread.Sleep(500);
                }
            }

    For the above code, you couldn't execute button1.PerformClick from other thread.

    private void button1_Click(object sender, EventArgs e)
            {
                Test();
            }
            public void Test() {
                int i = 0;
                while (true)
                {
                    Console.WriteLine(i++);
                    Thread.Sleep(500);
                }
            }

    you could access test method rather than invoke button1.PerformClick from other thread. Of course it doesn't block the UI thread.

    Thread thread = new Thread(form6.Test);
    
      thread.Start();

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Fei HuModerator Monday, November 13, 2017 10:35 AM
    • Marked as answer by mgppgm Monday, November 13, 2017 2:22 PM
    Monday, November 13, 2017 10:35 AM
    Moderator
  • Thank you for the information! I'm not sure this will actually solve my particular problem. But I was asking for advise. The crossthreaded issues I have run into before and this was a good reminder. I am marking this as the answer as you took time to respond in a helpful manner. Thank You!
    Monday, November 13, 2017 2:26 PM