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
  1. Home
  2. Web Development
  3. ASP.NET
  4. ASp.Net and Threading

ASp.Net and Threading

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-net
7 Posts 2 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.
  • P Offline
    P Offline
    pakFari
    wrote on last edited by
    #1

    Hi, I am trying to use thread in my ASP.Net application and facing some problem. I want to monitor a Application[“variable”] variable, for this I am using following code in thread start method. private void monitor() { /*compare the application variable with monitorStartGame*/ while(monitorStartGame.Equals(Convert.ToInt32(Application["startGame"]))) { } Label1.Text="thread ended"; } but it does not stop even the values is changed, and the text of Label1 is not changed. Plz help me I will be grateful to u.

    W 1 Reply Last reply
    0
    • P pakFari

      Hi, I am trying to use thread in my ASP.Net application and facing some problem. I want to monitor a Application[“variable”] variable, for this I am using following code in thread start method. private void monitor() { /*compare the application variable with monitorStartGame*/ while(monitorStartGame.Equals(Convert.ToInt32(Application["startGame"]))) { } Label1.Text="thread ended"; } but it does not stop even the values is changed, and the text of Label1 is not changed. Plz help me I will be grateful to u.

      W Offline
      W Offline
      Wyxlwiis
      wrote on last edited by
      #2

      Well there seem to a few problems with your code 1. if you don't wanna kill the server completely u'll need a Thread.Sleep() statement in the while loop. 2. Remember when u load the page u are initialiseing all controls everytime so Label1 will reset to u'r default value so u will have to have an Application or Session variable to keep the new value and set Label1.Text to that value in pageload. Wyx :-D

      P 1 Reply Last reply
      0
      • W Wyxlwiis

        Well there seem to a few problems with your code 1. if you don't wanna kill the server completely u'll need a Thread.Sleep() statement in the while loop. 2. Remember when u load the page u are initialiseing all controls everytime so Label1 will reset to u'r default value so u will have to have an Application or Session variable to keep the new value and set Label1.Text to that value in pageload. Wyx :-D

        P Offline
        P Offline
        pakFari
        wrote on last edited by
        #3

        thankx for u r reply;i agree with the 1st point, but in 2nd there is some confusion. i run the thread after a long time of page load and one more thing the following code also not show response in the threead while loop >> Response.Write("asdasd"); please explane the Lable1.Text problem, i will be very thankfull to u.

        P W 2 Replies Last reply
        0
        • P pakFari

          thankx for u r reply;i agree with the 1st point, but in 2nd there is some confusion. i run the thread after a long time of page load and one more thing the following code also not show response in the threead while loop >> Response.Write("asdasd"); please explane the Lable1.Text problem, i will be very thankfull to u.

          P Offline
          P Offline
          pakFari
          wrote on last edited by
          #4

          plz can u reply me soon, i will be very thankful to u.

          1 Reply Last reply
          0
          • P pakFari

            thankx for u r reply;i agree with the 1st point, but in 2nd there is some confusion. i run the thread after a long time of page load and one more thing the following code also not show response in the threead while loop >> Response.Write("asdasd"); please explane the Lable1.Text problem, i will be very thankfull to u.

            W Offline
            W Offline
            Wyxlwiis
            wrote on last edited by
            #5

            Well here's point even if ur' running a thread the server can not call the client with the response.write u see Web is a Request Reply protocol and the only way for u to get the value that is set by the thread is to Request the page and get the value set by the thread. Did u try to set a fx Application["myValue"] in the thread to fx "ThreadSet" and in pageload set the value af Label1.Text to Session["myValue"] I understand what u'r trying to do but that is not possible in Web u'll have to resolve to an TCP/IP solution so to explain it kiss if you are running thread in a web application any value set in the thread has to be keept in a typ of variable on the server that maintain its value between request every time u make a request you will have to set the control value to that value. BR Wyx

            P 1 Reply Last reply
            0
            • W Wyxlwiis

              Well here's point even if ur' running a thread the server can not call the client with the response.write u see Web is a Request Reply protocol and the only way for u to get the value that is set by the thread is to Request the page and get the value set by the thread. Did u try to set a fx Application["myValue"] in the thread to fx "ThreadSet" and in pageload set the value af Label1.Text to Session["myValue"] I understand what u'r trying to do but that is not possible in Web u'll have to resolve to an TCP/IP solution so to explain it kiss if you are running thread in a web application any value set in the thread has to be keept in a typ of variable on the server that maintain its value between request every time u make a request you will have to set the control value to that value. BR Wyx

              P Offline
              P Offline
              pakFari
              wrote on last edited by
              #6

              Hi, please check it out this code; I am trying to monitor an Application[“startGame”] vaiable for this I wrote a class that lie in WebForm1 : System.Web.UI.Page class private void Page_Load(object sender, System.EventArgs e) { Label1.Text=Session["threadCheck"].ToString(); monitorStartGame=Convert.ToInt32(Application["startGame"]); } class myThread { public WebForm1 web; public object obj; public System.EventArgs ex; public void monitor() { while(monitorStartGame != Convert.ToInt32(web.Application["startGame"])) { Thread.Sleep(TimeSpan.FromSeconds(2)); } web.Session["threadCheck"]=100000; web.Page_Load(obj,ex); } } now when I click the button to start monitoring the following code execute static Thread thread; private void Button12_Click(object sender, System.EventArgs e) { myThread th = new myThread(); th.obj = sender; th.ex=e; th.web=this; thread = new Thread(new ThreadStart(th.monitor)); thread.Start(); } >> Now I open another explorer (using same address) and click another button to change the Application variable private void Button13_Click(object sender, System.EventArgs e) { Application["startGame"]=1000; monitorStartGame=12; } but nothing happen on my previous explorer page (even the vale of Application variable is changed now) and if I change the vale through one explorer it works. I tried to explain my problem I think u can trace out the solution, please give me a solution to this problem. thanx

              P 1 Reply Last reply
              0
              • P pakFari

                Hi, please check it out this code; I am trying to monitor an Application[“startGame”] vaiable for this I wrote a class that lie in WebForm1 : System.Web.UI.Page class private void Page_Load(object sender, System.EventArgs e) { Label1.Text=Session["threadCheck"].ToString(); monitorStartGame=Convert.ToInt32(Application["startGame"]); } class myThread { public WebForm1 web; public object obj; public System.EventArgs ex; public void monitor() { while(monitorStartGame != Convert.ToInt32(web.Application["startGame"])) { Thread.Sleep(TimeSpan.FromSeconds(2)); } web.Session["threadCheck"]=100000; web.Page_Load(obj,ex); } } now when I click the button to start monitoring the following code execute static Thread thread; private void Button12_Click(object sender, System.EventArgs e) { myThread th = new myThread(); th.obj = sender; th.ex=e; th.web=this; thread = new Thread(new ThreadStart(th.monitor)); thread.Start(); } >> Now I open another explorer (using same address) and click another button to change the Application variable private void Button13_Click(object sender, System.EventArgs e) { Application["startGame"]=1000; monitorStartGame=12; } but nothing happen on my previous explorer page (even the vale of Application variable is changed now) and if I change the vale through one explorer it works. I tried to explain my problem I think u can trace out the solution, please give me a solution to this problem. thanx

                P Offline
                P Offline
                pakFari
                wrote on last edited by
                #7

                please reply me soon i shall be thankful to you.

                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