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 59537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:01:15+00:00 2026-05-10T18:01:15+00:00

Here’s the situation: I’m developing a simple application with the following structure: FormMain (startup

  • 0

Here’s the situation: I’m developing a simple application with the following structure:

  • FormMain (startup point)
  • FormNotification
  • CompleFunctions

Right?

Well, in FormMain I have the following function:

private void DoItInNewThread(ParameterizedThreadStart pParameterizedThreadStart, object pParameters, ThreadPriority pThreadPriority) {     Thread oThread = new Thread(pParameterizedThreadStart);     oThread.CurrentUICulture = Settings.Instance.Language;     oThread.IsBackground = true;     oThread.Priority = pThreadPriority;     oThread.Name = 'μRemote: Background operation';     oThread.Start(pParameters); } 

So, everytime that I need to call a time consuming method located on ComplexFunctions I do the following:

// This is FormMain.cs string strSomeParameter = 'lala'; DoItInNewThread(new ParameterizedThreadStart(ComplexFunctions.DoSomething), strSomeParameter, ThreadPriority.Normal); 

The other class, FormNotification, its a Form that display some information of the process to the user. This FormNotification could be called from FormMain or ComplexFunctions. Example:

// This is ComplexFunctions.cs public void DoSomething(string pSomeParameter) {     // Imagine some time consuming task     FormNotification formNotif = new FormNotification();     formNotif.Notify(); } 

FormNotify has a timer, so, after 10 seconds closes the form. I’m not using formNotif.ShowDialog because I don’t want to give focus to this Form. You could check this link to see what I’m doing in Notify.

Ok, here’s the problem: When I call FormNotify from ComplexFunction which is called from another Thread in FormMain … this FormNotify disappears after a few milliseconds. It’s the same effect that when you do something like this:

using(FormSomething formSomething = new FormSomething) {    formSomething.Show(); } 

How can avoid this?

These are possible solutions that I don’t want to use:

  • Using Thread.Sleep(10000) in FormNotify
  • Using FormNotif.ShowDialog()

This is a simplified scenario (FormNotify does some other fancy stuff that just stay for 10 seconds, but they are irrelevant to see the problem).

Thanks for your time!!! And please, sorry my english.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T18:01:16+00:00Added an answer on May 10, 2026 at 6:01 pm

    Almost every GUI library is designed to only allow calls that change the GUI to be made in a single thread designated for that purpose (called the UI thread). If you are in another thread, you are required to arrange for the call to change the GUI to be made in the UI thread. In .NET, the way to do that is to call Invoke (synchronous) or BeginInvoke (asynchronous). The equivalent Java Swing call is invokeLater() — there are similar functions in almost every GUI library.

    There is something called thread affinity. There are two threads in a WinForm Application, one for rendering and one for managing user interface. You deal only with user interface thread. The rendering thread remains hidden – runs in the background. The only objects created on UI thread can manipulate the UI – i.e the objects have thread affinity with the UI thread.

    Since, you are trying to update UI (show a notification) from a different thread than the UI thread. So in your worker thread define a delegate and make FormMain listen to this event. In the event handler (define in FormMain) write code to show the FormNotify.

    Fire the event from the worker thread when you want to show the notification.

    When a thread other than the creating thread of a control tries to access one of that control’s methods or properties, it often leads to unpredictable results. A common invalid thread activity is a call on the wrong thread that accesses the control’s Handle property. Set CheckForIllegalCrossThreadCalls to true to find and diagnose this thread activity more easily while debugging. Note that illegal cross-thread calls will always raise an exception when an application is started outside the debugger.

    Note: setting CheckForIllegalCrossThreadCalls to ture should only be done in DEBUGGIN SITUATIONS ONLY. Unpredicatable results will occur and you will wind up trying to chase bugs that you will have a difficuly tome finding.

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

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Yes, the MSDN documentation should read 'obtains the next element'.… May 11, 2026 at 10:43 am
  • added an answer Paolo is right, but I would also add that the… May 11, 2026 at 10:43 am
  • added an answer The array you are showing is the Fourier Transform coefficients… May 11, 2026 at 10:43 am

Related Questions

Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here is my code, which takes two version identifiers in the form 1, 5,
Here's a coding problem for those that like this kind of thing. Let's see
Here is the scenario: I'm writing an app that will watch for any changes
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here we go again, the old argument still arises... Would we better have a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.