Long enough time between calling the dispatcher and executing

I apologize in advance if this is a stupid question. I am a C programmer by profession, and C # is relatively new.

I have an application that basically boils down to the following: one thread that checks the external interface (profibus in case someone is interested), when the input changes the event and new data is raised. Because the data I need to update uses data binding. I call the dispatcher. This setting works properly millions of times, but sometimes it takes up to 6 seconds before the code is executed in deletion. Since there are no other threads, I see no reason for this. I am using the following event handler. A container is a reference to a TabItem for which the class is bound to a database.

public void newSlave_InputChanged(object sender, InputChangedEventArgs e)
    {
        DateTime beforeDisp = DateTime.Now;
        Container.Dispatcher.Invoke(DispatcherPriority.Send, (Action)delegate()
        {
            DateTime afterDisp = DateTime.Now;
            if (afterDisp.Subtract(beforeDisp).TotalSeconds > 1)
            {
                /* Breakpoint here to detect the problem */               
            }
            /* Do the work I need to do */           

        }
    );
    }

:

void monitorSlaves()
    {
        while (true)
        {
            if (cardOnline)
            {
                foreach (slave slv in slaves)
                {
                    /* get the data */
                        if (dataChanged)
                        {
                            /* raise event */
                        }
                    }
                }
                Console.WriteLine(string.Format("{0}: Monitor slaves", DateTime.Now));
            }
            Thread.Sleep(200);
        }
    }

, , , "". , . , , , . , 2010 , intellitrace .

.

+3
3

thread.sleep, , , , . DispatcherTimer

0

, , , ?

, DLL .

, , . , 6 - , .

, . Trace.TraceInformation, . DebugView, . DebugView .

P.S. , .NET, .:)

0

, - , . perfmon .

0

Source: https://habr.com/ru/post/1782769/


All Articles