|
I'd bet money that all page processing occurs on one thread.
I did find this on google.
http://dotnet.org.za/armand/archive/2004/04/07/985.aspx[^]
So it seems you could store and pass data using the CallContext, however judging that only 4 results come back when you google System.Remoting.Runtime.Messaging.CallContext you might have trouble getting any help with this.
I didn't get any requirements for the signature
|
|
|
|
|
We're pretty much doing the same thing. It is perfect for providing "execution context" information like who is the current user, what's the current database, and so on.
I'm going off on a tangent here, but I actually believe what we've done can be quite useful for others as well.
Our design follows this simple pattern: All instance members are private, as are all constructors. The public interface is static, but public members do nothing but find the right instance and call the corresponding instance member. References to instances are stored in the thread context, hence only one thread can access each instance, so the design is inherently thread-safe.
A snippet demonstrates the pattern implemented in C#:
public class Connection
{
const string threadKey = "Connection";
Connection(string cnxStr) { ... }
int transactionLevel;
SqlTransaction transaction;
SqlConnection sqlConn;
...
void beginTransaction()
{
...
}
Connection current
{
get
{
Connection c = CallContext.GetData(threadKey) as Connection;
if (c == null)
{
string cnxStr = ...;
c = new Connection(cnxStr);
}
return c;
}
}
static public void BeginTransaction()
{
current.beginTransaction();
}
}
We couple this with our own custom-written "Thread class" (Thread is sealed so our type is not really a thread, but it has the same interface as a thread so where our code was creating threads we just switched the type to our own) which copies the execution context of the thread that creates it, and we have a wonderfully simple to use solution with a minimum of code redundancy. (The "where do connection info come from" logic was all over the place before, and we had problems knowing when we should clone connections and when we should not, because the method using a connection would sometimes be called as part of a transaction and sometimes without one, sometimes in a thread processing a page request and sometimes in a background thread... Using the call context and our pretend-thread class solved all these problems and simplified the programming of application logic to boot!
The code it leads to is just as simple as code reading or writing a Session variable, though of course there are many session instances at any given time in the application domain. Only it is even better because no reference to the object exists outside the type itself, making it far easier to avoid memory leaks.
In the past we even had business objects that contained a reference to an instance of HttpSessionState,
myObj.Session = Session;
and this sort of terrible thing too is avoided with this design, at the expense of a larger number of lookups of course. The overhead doesn't seem to be that big though. In 1.x the HttpContext.Current also came from here (I checked with Reflector) so I'm figuring it can't be that bad.
This of course is all proprietary information
|
|
|
|
|
Nice.
You might want to write up an article about this...
I didn't get any requirements for the signature
|
|
|
|
|
Hi guys
I have a function called SendEmail which runs within a thread.
This function simply send an email to the user.
However, I made a "Please Wait..." page while the email gets send in the background the user see the "Please Wait..." page.
<br />
public void SendEmail()<br />
{<br />
StringBuilder messageText = new StringBuilder();<br />
<br />
messageText.AppendLine(string.Format("Name: {0} {1}", txtName.Text.Trim().ToString(), txtSurname.Text.Trim().ToString()));<br />
messageText.AppendLine(string.Format("Contact Number: {0}", txtContactNumber.Text.Trim().ToString()));<br />
messageText.AppendLine(string.Format("Email Address: {0}", txtEmail.Text.Trim().ToString()));<br />
messageText.AppendLine(string.Format("Comments: {0}\n\n", txtComments.Text.Trim().ToString()));<br />
messageText.AppendLine(string.Format("Quote Reference Nr: {0}", Request.QueryString["quoteNr"].ToString()));
<br />
}<br />
I call the SendEmail() function using the following lines of code:
<br />
Guid id = Guid.NewGuid();<br />
<br />
ThreadStart ts = new ThreadStart(SendEmail);<br />
<br />
Thread th = new Thread(ts);<br />
<br />
th.Start();<br />
<br />
Response.Redirect(string.Format("PleaseWait.aspx?ID={0}&type={1}", id, "email"));<br />
Is it true that you can't access Request data within a thread, if not, how do I then get access to Request.QueryString data?
|
|
|
|
|
Hi,
all code runs within a thread or another the difference is just that you explicitly created the one from which you want to send mail.
It makes no sense for the request to be available outside the "main" thread (the one created by asp.net rather than your code) since the asp.net model is to free all the resources used for a specific request once the response has been sent. It is possible to hack it by keeping your own references to it, but that would be bad to say the least, and not only for performance - you'll never know if the state of the object is good or not, it might be disposed or even reused in a pool for all we know, today or in a future version of ASP.NET.
However, all your method neeeds is to know the quote reference number, so the solution is to make it get this from somewhere other than the request. If you're using at least v2.0 you can use the parameterized thread start delegate and you're done. In 1.x a somewhat more sophisticated solution must be invented, such as using a synchronized ArrayList.
All of this having been said, because I'm such a nice bloke and want you to understand the problem and how one can solve it, I have to say that it is utterly nonsensical to make a new thread for what your sendmessage method is doing. It is not only needlessly complicated but the overhead of creating and starting the thread is huge compared to the amount of work performed in the thread, so its a performance killer to boot. Right here therefore, the solution is simply to get rid of your multithreaded design where a singlethreaded one is far better.
|
|
|
|
|
DON'T CROSS POST You were given answers in the original post.
only two letters away from being an asset
|
|
|
|
|
hi everyone,
Can anyone plz give me a regular expression of strictly (999) 999-9999 format. I've tried to modify the one available in VS .NET 2005 but couldnt do so.
Thanks
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
hi Rocky#,
Moast of the time i have failed due to lacking in the understanding of Regular Expression. So, i downloaded a software which contains a library of REGEX (Regular Expressions), from that i found REGEX of your need.
\((?<AreaCode>\d{3})\)\s*(?<Number>\d{3}(?:-|\s*)\d{4})
Hope this help you. To download this software free of cost try this link.
http://www.ultrapico.com/Expresso.htm
Make other people to aware of such software.
Thanks & Regards
Dilip Kumar Vishwakarma
|
|
|
|
|
Thanks a lot, thats a lot of help,
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
Hi all, quite new to asp.net c# programming, i have a mifare reader PCR310U , i need to develop a website which can retrieve information(like card ID) through website using remote mifare reader in remote computer when surfing the website.
for example, i already published my website, when i'm not at the server computer and at my own house, i have a mifare card reader which is connected to my house's PC and a mifare Card, i wish to register the card ID together with my IC number and save into my system website database. can anyone enlighten me on how to go about doing it?i really have no idea how i can retrieve information through mifare reader through the internet website.
if you can help me pls email me.this system quite urgent for me.
thanks alot
tyrone
tyrone_93@Hotmail.com
|
|
|
|
|
Do not post the same message to multiple forums. See the CodeProject Posting Guidelines.
led mike
|
|
|
|
|
Can any one of u know how to open outlook from asp.net , without "mailto:" function , coz i want to send html page with that outlook
|
|
|
|
|
You can construct a mail message and send it using SmtpMail.
MailMessage msg = new MailMessage();<br />
msg.BodyFormat = MailFormatHtml;<br />
msg.Body = "<html><body>Hello</body></html>";<br />
msg.To = "someone@someplace.com";<br />
SmtpMail.Send(msg);
only two letters away from being an asset
|
|
|
|
|
no ! i want to open outlook with the web page that i give !
thnx in advance
|
|
|
|
|
Perhaps you would like to restate your question and explain exactly what you looking for.
only two letters away from being an asset
|
|
|
|
|
You can open a web version of outlook if your exchange server is set up to serve it. Otherwise, no.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I designed a localreport with a number of columns but would like to show or hide columns at runtime using a report parameter which I set through the aspx page. How do I set the column visiblity at design/runtime according to the parameter value?
|
|
|
|
|
Can you use an IIF expression in the visibility property?
|
|
|
|
|
Thanx,
I did the following: In the tableColumn visiblity i managed to add an IIf expression which test the parameter. Thanx again, Corna
|
|
|
|
|
Thanks Corna, but can u give me a sample code as how u are disabling a column, my problem is I don't want to show column when viewing a report, but when exporting it needs to be there as hidden column in EXCEL.
Anshul
|
|
|
|
|
Didn't try/need this before, I will see if I can find something like this.
|
|
|
|
|
Hi,
Do you by any change have an example of how to print a local report. I've tried the msdn example but can't seem to get it working.
Thanx
|
|
|
|
|
following is the coding which works fine in local machine / but after i made host this on server, it shows "Mail sent successfully" but no mails received in my inbox!
can any one solve this problem!
thnx in advance!
Dim mssg As New System.Web.Mail.MailMessage
mssg.BodyFormat = Web.Mail.MailFormat.Html
mssg.To = txtTo.Text
mssg.From = txtFrom.Text
mssg.Subject = txtSubject.Text
mssg.Body = strMessage
System.Web.Mail.SmtpMail.Send(mssg)
|
|
|
|
|
|
You may need to specify a mail server.
|
|
|
|