Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 15th, 2007, 09:55 AM
Authorized User
 
Join Date: May 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to swifty_programmer
Default threading

Hi all,
I'm looking for some good tutorials for threading in ASP.NET 2.0 C#
I know what a thread is, I can make one and make it doing some calculation work, but that's it.
In fact I want to start a thread in MethodA() and let him do the work in MethodB() (no parameters) after waiting 3 seconds.
Seems simple, but I know that to acces controls and variables in QeurryString you have to to Delegate.BeginInvoke... because the main thread locks the controls & propreties from other threads. And honestly, I don't know nothing about delegates (apart that they are signatures to method) and nothing about callbacks (sync or assync) and not so much about threading.
Can someone help me?
 
Old May 15th, 2007, 10:42 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Generally speaking, threading is not used very much in ASP.NET. Mainly this is because of the nature of how web applications work. You can't spin off a thread and have it do work in the background and get updates to controls because the conversation with the browser is over after the first thread returns. There is a way to do asynchronous page processing but I'm not to familiar with that.

-Peter
 
Old May 15th, 2007, 10:43 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

For your viewing pleasure:

http://www.google.com/search?hl=en&s...essing&spell=1

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 15th, 2007, 03:46 PM
Authorized User
 
Join Date: May 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to swifty_programmer
Default

thx for the replies.
I've simply told the thread to sleep for 5 seconds before returning the webpage.
My button calls the function with the Thread.Sleep(...)
this produced a first postback that tells the user that his request is successfully sent and 5 seconds later the method produces a second postback with the result.

That's good enough for me :)

Cheers

 
Old May 15th, 2007, 06:37 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

That doesn't make sense to me. Sleeping a thread isn't going to create a second postback. It's just going to delay the thread.

What exactly are you trying to achieve? Are you experimenting with threads or are you trying to find a solution to something?

-Peter
 
Old May 16th, 2007, 01:47 AM
Authorized User
 
Join Date: May 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to swifty_programmer
Default

Hi, I'm working on a solution to get data and show it to the user.
In short: The page sends a message to a mobile black-box device (via IRemoting) and it takes a few seconds for the device to answer, so I just wait after sending the message for 3 seconds before getting the data from the database (where the device sends it messages (via a server application)).
this is the method I'm calling after done some work first:

private void GetResultsOfCommand()
        {
            Thread.Sleep(TimeSpan.FromSeconds(3));

            //Get the results of the send-commando's
            InboundDataInfoCollection serverReports = InboundData.GetLastByUnitId(UnitId, 5);
            _gvServer.DataSource = serverReports;
            _gvServer.DataBind();
            _pResultsSendCommand.Visible = (_gvServer.Rows.Count > 0);
        }

As you see it isn't the Thread.Sleep() that makes the postback but the GridView.Databind() (I think). Whatever it is, it's working fine :)
 
Old May 16th, 2007, 07:21 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

No server code can create a postback. Inherently, a postback is a client initiated action. (Yes, you can emit client script that will trigger a postback, but ultimately it's fired at the client.)

I guess I just don't see what the point of this thread sleep is. You might as well let the program run as fast as it can. If there is a delay in device response, the program will delay anyway. But if there isn't a delay, why make it wait?

-Peter
 
Old May 16th, 2007, 08:14 AM
Authorized User
 
Join Date: May 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to swifty_programmer
Default

Hi,
The delay caused by the slow gprs connection of the device causes no delay in the webpage because it communicates INdirectly with the webpage. All communication comming back from the device is going to a server app. This server app. stores everything in a DB.
And my webpage gets the data from that DB. So if you go to quickly the data isn't stored in the DB yet. And the user might think his command was not send successfully. That's why I have to wait 3 seconds after sending a command, to get the fresh data from the DB.
I hopes this clears things out.
 
Old May 16th, 2007, 08:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Delaying a process could be a painful thing is your server has heavy load, this thing could work until it stop working and the server crash... you might better try to find a better solution..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 16th, 2007, 10:40 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What database are you using?

MSSQL2005 allows for ASP.NET SQL server table cache dependencies. Therefore, there must be some mechanism that monitors table activity (similar to a FileWatcher class). If you could use a "TableWatcher" you could have a blocking call (that is, a method call that waits until something happens, in other words: any synchronous call) stop the page processing until the table is updated with the desired data. This way the process can run as fast as possible while still getting what you need.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
threading bschleusner C# 2005 2 April 12th, 2007 08:40 AM
Multi-threading issue Bill Crawley Pro Visual Basic 2005 0 March 21st, 2007 06:19 AM
multi threading rashid.shaban@gmail.com BOOK: ASP.NET Website Programming Problem-Design-Solution 1 February 26th, 2007 11:48 PM
Threading kramis8 C# 1 April 27th, 2005 04:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.