Click here to Skip to main content
14,693,117 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
wpf windows unresponsive because of threading
Posted
Comments
OriginalGriff 23-Feb-15 5:07am
   
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Member 8806421 23-Feb-15 5:17am
   
this is my code when i call this on button then wpf unresponsive

Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
{

while (_continue == true)
{
if (!port.IsOpen)
{
port = new SerialPort(CmbComPort.SelectedItem.ToString());
port.Open();
}


message = port.ReadExisting();
if (message.Length > 0 && message.Length >= 15)
{
if (message.Contains("^"))
{
AA = message.Substring(1, 2);

ThreadWrite();
}
else
{

_continue = false;
}

}

1 solution

Read the documentation: https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.invoke(v=vs.110).aspx[^]
"Dispatcher.Invoke Method

Executes the specified delegate synchronously on the thread the Dispatcher is associated with."

So if you are executing that code on your UI thread, then the UI will stop responding until it exits the loop.

Try using the SerialPort.DataRecieved[^] event and processing the data character by character instead.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900