Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Multi thread, one dialog form [modified]

Multi thread, one dialog form [modified]

Scheduled Pinned Locked Moved C#
helpwinformsperformancequestioncode-review
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yunusdemiray
    wrote on last edited by
    #1

    Hi, i have a problem about threads with windows forms. When users's sessions ended, i want to show a dialog box to inform them to relogin and then to show the relogin form. It was ok until i use threads in some forms to improve performance. When a thread reveices a session error, it shows the relogin form. Actualy i use invoke on the main thread. But while the dialog form is shown, another thread can make a service call and receive the same session error and so tries to show the same relogin form. But it is clear that only one instance of relogin form must be shown at the same time. So i have to use a locking mechanism. But since the thread that shows the dialog box is the main thread, this causes the main thread enter wait state. So the application freezes.

    public bool Relogin() {
    	Interlocked.Increment(ref waitingThreadCount);
    	event1.WaitOne();/\*Auto Reset Event\*/
    	if(this.loginResult == null) {/\*login result is type of bool?\*/
    		loginResult = ReloginForm.Show();//Runs as modal
    	}
    	Interlocked.Decrement(ref waitingThreadCount);
    	if(waitingThreadCount == 0) {
    		loginResult = null;
    	}
    	event1.Set();
    	return loginResult.Value;
    }
    

    modified on Thursday, June 11, 2009 2:40 AM

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups