© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
8 replies
De1337

freeze winform app until loop exits

I have an app running and when a specific button is hit it runs a bunch of tasks. I want to freeze the tasks at one point until a loop is finished. Not sure why this code isn't doing that:

loop = true;

    //loop while receiving data to prevent going past this point until the end
    while (loop == true)
    {
        //upon data receipt from tracer, send data to dataReceivedHandler function
        port.DataReceived += new SerialDataReceivedEventHandler(dataRecievedHandler);
    }
loop = true;

    //loop while receiving data to prevent going past this point until the end
    while (loop == true)
    {
        //upon data receipt from tracer, send data to dataReceivedHandler function
        port.DataReceived += new SerialDataReceivedEventHandler(dataRecievedHandler);
    }


Later in the code I have a loop=false in my dataReceivedHandlerFuntion to break the loop but code after this code is executing prematurely
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

while() loop exits after first run [Answered]
C#CC# / help
4y ago
✅ bug in my winform app
C#CC# / help
2y ago
Switching between forms in WinForm app
C#CC# / help
12mo ago