Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8104449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:50:45+00:00 2026-06-05T23:50:45+00:00

I have a question about solving UI freezing. Introduction: I am currently programming an

  • 0

I have a question about solving UI freezing.

Introduction:
I am currently programming an OPC based online alarm reader for a given analyzer tool. This tool received data from an excel sheet, analyzed this data using a rule base and a topology model and shows the results with TreeViewItems.
My task is to replace the excel sheet reader by a real time alarm reader.
That’s done, I can connect my software to server and receive data packages every time new alarms are created.

Problem:
My solution for transport the new data to the main class and from there to the analyzer class is saving the data in a list, adding them to an EventArgs and raising an Event. The handling method in the main class receives this data, starts a new task (Task>) for the analyzer and returns its results to the Main Thread.
This construction should have uncoupled the calculation process from the UI The analyzing process takes about 1.3s with example data. New data arrives every 2 seconds on average. 2 seconds is in the same time the highest refreshing time.

Attached is a code snippet from the handling method

    Task<List<Analyser.ALARM_GROUP>> analysertask = Task.Factory.StartNew<List<Analyser.ALARM_GROUP>>(
                    ()=>
                        {
                            /*if the alarmlist is emty, set the new alarms as alarmlist, 
                             * else add the new alarms to the present list*/
                            if (AlarmList1.Count == 0)
                                AlarmList1 = e.CurrentAlarms;

                            else listModifier.mergeList(e.CurrentAlarms, AlarmList1);

                            /*Start the analysis process in a seperate task and return the Alarm_Group-List*/
                            return Analyser1.startAnalysis(PlantModelReader1, AlarmlogReader1, RuleBaseLoader1, AlarmList1); 
                        });

                Cursor = Cursors.Wait;
                List<Analyser.ALARM_GROUP> alarmGroupList = analysertask.Result;

                showAlarmLog(alarmGroupList);

                Cursor = Cursors.Arrow;

Unfortunately the UI still is stuck when I start analyzing process and I don’t even know if my concept of starting a new thread every two seconds(average appearance time of new alarms) is a reasonable concept.
I guess the problem is inside showAlarmLog but it is a lot of code. If needed I will post this code, too.

I would be thankful for any suggestions on this problem, even a “your concept is crap, try this idea: …” would be good to know.

Kind regards
Larimow

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:50:48+00:00Added an answer on June 5, 2026 at 11:50 pm

    The problem is that this call:

    List<Analyser.ALARM_GROUP> alarmGroupList = analysertask.Result;
    

    Blocks the UI thread until the background task is completed.

    The way to handle this is to use a continuation task instead of waiting on the result:

    Task<List<Analyser.ALARM_GROUP>> analysertask = Task.Factory.StartNew<List<Analyser.ALARM_GROUP>>(
        ()=> {
            // Keep existing code
            return Analyser1.startAnalysis(PlantModelReader1, AlarmlogReader1, RuleBaseLoader1, AlarmList1); 
             });
    
    // Make a continuation here...
    analysertask.ContinueWith( t =>
        {
            Cursor = Cursors.Wait;
            List<Analyser.ALARM_GROUP> alarmGroupList = t.Result;
            showAlarmLog(alarmGroupList);
            Cursor = Cursors.Arrow;
        }, TaskScheduler.FromCurrentSynchronizationContext());
    

    By scheduling this as a continuation, it will run when the first task completes. By using TaskScheduler.FromCurrentSynchronizationContext, you say to marshal this back onto the UI thread when it executes.


    Note that this becomes far easier with .NET 4.5/C# 5. With C# 5, you could write this as:

    var analysertask = Task.Run(
        ()=> {
            // Keep existing code
            return Analyser1.startAnalysis(PlantModelReader1, AlarmlogReader1, RuleBaseLoader1, AlarmList1); 
             });
    
    Cursor = Cursors.Wait;
    List<Analyser.ALARM_GROUP> alarmGroupList = await analysertask;
    showAlarmLog(alarmGroupList);
    Cursor = Cursors.Arrow;
    

    This requires the method to be, itself, flagged with the new async keyword, however.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is all about solving a SslPolicyError.RemoteCertificateNotAvailable error. I have developed a TCP
I have question about sending emails from MVC3 application. I already read for exmple
I have question about how I can save the result of function I have
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,
i have question about YAJLiOS parser... I have next json data : {{ body
I have a question about how the System class works. Lets say there is
I have a question about intent in android application i have an array in
I have a question about what would be the best practice for creating a
I have a question about using session, or maybe TempData to store data while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.