Geeks With Blogs

News
About Me:
I am a Female SharePoint Developer (a platinum unicorn). I have been working with SharePoint since I attended the Portal University in 2005. I hold a BA in Computer Science from the University of Missouri - Kansas City. I love playing Rockband, organizing user group meetings, working with code, attending events as a speaker or organizer, and having bizarre conversations about geek things with cool people. If you have any comments or questions fill out the contact form and I will try my best to help.



The Guide of a MOSSLover Becky Isserman's Blog
I am researching multi-threading in ASP .Net 2.0, because I have a special Site Creation Web User Control that I created and I want to show a loading screen.  So far I have watched the dnrTV(http://www.dnrtv.com) video on multi-threading in a Windows Application.  I thought you could do this in ASP .Net, unfortunately that is not the case.  Does anyone know a good multi-threading reference?  If so, let me know and in return I will post a little example on how I would create the loading screen in co-existence with the site creation.
Also, if anyone wants me to re-visit site creation using some query string parameters and a web service to get users let me know.  I know that I have posted using SQL Server.  This is just another way to use C# and Query Parameters in a Web User Control (or web part). Posted on Monday, April 14, 2008 3:48 PM MOSS | Back to top


Comments on this post: Multi-Threading: How do I do that?

# re: Multi-Threading: How do I do that?
Requesting Gravatar...
Hi Becky,

If I understand correctly, you want a web page to load in the client's browser, then have the place where your user control is to show a loading screen whilst the contents get pulled over from a web service?

Although threading in winforms uses the same code and structure, how you apply them in aspnet is quite different. Based on what you're doing, you don't need to use threading anyway. Instead, you'll need to display the page with the loading screen visible, and utilize javascript to fetch data from the webservice once the page is loaded and then display the data on the screen & trash the loading box.

As this is done client side in the browser, you wouldn't need to use server side threads.

Hope I've understood your post correctly.
Left by Andrew on Apr 14, 2008 8:58 PM

# re: Multi-Threading: How do I do that?
Requesting Gravatar...
Well, it's a little different...What the user control is doing is creating a SharePoint Site in the Page Load event, then it redirects to the actual site. I probably should just change the code so that the page loads with some type of loading screen and then triggers the event. Maybe some type of onafterload event or onrender. You do give an interesting idea though with the client side script. I always love it when someone from GWB Posts, because you guys seem to know your stuff pretty well. Thanks for the suggestion. It sounds intriguing and thanks for the post.
Left by MOSSLover on Apr 14, 2008 9:04 PM

# re: Multi-Threading: How do I do that?
Requesting Gravatar...
I had a hunch it wasn't going to be as easy as that.

Not to worry. You don't actually need to do any of this stuff with threads still, but I've done an example to show how you can create your site in a seperate thread.

In the page load event you kick of the thread that creates your Moss site, but make sure to use thread.join() so that your page doesn't finish its response before the site is created.

While the site's being created, you can use the Response.Write() and Response.Flush() to report the progress to the browser.

Finally when the site is created and that worker thread , you'll be back on your main thread where you want to Response.Write() some javascript to redirect the browser to wherever.

The code will look something like this:

protected void Page_Load(object sender, EventArgs e)
{
StartThread();
}

private void StartThread()
{
Response.Clear();

ThreadStart ts = new ThreadStart(CreateThread);
Thread t = new Thread(ts);
t.Start();

lock (Response)
{
Response.Write("<html><body>Loading...<br />");
Response.Flush();
}

t.Join();

Response.Write("Finished. Redirecting in 1sec<br />");
Response.Flush();

Thread.Sleep(1000);

Response.Write(@"<script type='text/javascript'>document.location='about:home';</script></body>");
Response.End();
}

void CreateThread()
{
//create a new moss site
for (int progress = 0; progress < 100; progress += 10)
{
System.Threading.Thread.Sleep(100);
lock (Response)
{
Response.Write(string.Format("{0}% complete<br />", progress));
Response.Flush();
}
}

Thread.CurrentThread.Abort();
}

Good luck!
Left by Andrew on Apr 15, 2008 1:42 AM

Your comment:
 (will show your gravatar)


Copyright © MOSSLover | Powered by: GeeksWithBlogs.net