C# - Load Data To Application Domain Using A Thread?
Jan 22, 2011
I want to load data to my application domain using a thread so it will be executed at all times. How can I achieve this? I want the thread will start when iis starts and terminate when iis exits.
Note:
I want to do this so I can use disconnected architecture in my asp.net application.
Can someone explain me what is is the relationship between App Domain and thread? msdn says "threads are free to cross application domain boundaries; a new thread is not created for each application domain." suppose there is one thread t inside Appdomain a1 .there is an another App domain a2 .thread t can cross to a2 from a1 means it can access a2 memory area If thread can cross the app domain boundaries share the memory space then how application domain isolation is still there?
I need to call a function everytime a visitor visits one of my website's page. But I do not want the execution of the function to interfere with the interface between the user and the website i.e. different thread. What is the best way to do that on ASP.Net?
I want to remove checked items from checklistbox (winform control) in class file method which i am calling asynchronously using deletegate. but it showing me this error message:-
Cross-thread operation not valid: Control 'checkedListBox1' accessed from a thread other than the thread it was created on.
i have tried invoke required but again got the same error. Sample code is below:
My feeling says it's not posible but anyway I am curious if there is at least a workaround for accomplish this.Basically I am working at my client site and my machine is not connected to the domain.What I want to do is running a web application locally under a domain account, and using the webdev server.The webapp uses the default authentication, windows authentication that is.I tried using impersonation with domainuser & password but I got the following error Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'Logon failure: unknown user name or bad password.I have to mention that the username and the password are correct.
I have two domain servers X and Y.My Asp.net Web application is hosted on Domain X.But my scope is required to authorize the user of Domain Y on the Web application hosted on Domain X server.I am using Windows Authetication mode in application
I have a process in which a user uploads a file to a web site where the file is then processed and uploaded into the database. The process of validating the file could take several minutes so as soon as the file is uploaded I create a new thread and I do my processing on this second thread. This works great on my local machine but doesn't work at all on my IIS 7 test server.
After some investigating I found the problem is that the process is trying to load a reference to Castle and it can't find the DLL. I have a copy of Castle DLLs in my bin and it works elsewhere in my app. I ran Fuslog and discovered that it is trying to load castle from the wrong location. It is trying to load from c:/windows/system32/inetsrv/.
It appears that under IIS 7 the second thread is executing in a different context or something.
I have an application that initially display 4 grid views at page load. This process takes 50-60 seconds and I would like to change the process to display the web page, show message like "Data being loaded, please wait..." and then spin off a thread that fills the various grid view. When this is done I would programatically like to do a post back to show the result. Not sure if this is possible? I tried something like this:
Below is our error message. This happens around 5 - 7AM daily, and we are struggling with identifying the root cause. It's hard for me to believe it's code related, but anything's possible. Still, what's odd is the app runs fine for a day then an IIS reset is done and everything is fixed. Is there any way this could be related to code and has anyone dealt with this error before? Could a job or some permission being run behind the scenes be using this same dll and cause it to be overwritten?
Timestamp: 3/4/2010 12:11:23 PM Message: HandlingInstanceID: 3d9a795c-1256-44c1-b018-f553d4023b12 An exception of type 'System.TypeInitializationException' occurred and was caught.
There are two web applications App1 & App2. A user would submit his information on App1 though a form. On click of a specific button/link on App1, the same data should be posted to a page on App2 and the user should also be redirected to the same page on App2.I would like some help in finding out the best way to implement this functionality.
One of the approaches that I have already tried out is by creating a temporary HTML form at runtime, setting the action attribute of the form to the App2 Page and get the form posted by using javascript submit. The data can then be fetched on App2 page by using the response.form object.This approach works well, but i was still wondering if there is any other way to implement the required functionality.
give some insights on using RESTful webservices to implement this, or else, using some HttpModule to intercept requests at App1 and modify redirect response to app2 or any other approach that you might find fit for the purpose.
i want a continously running thread in my web application for sending mail to admin if the logged complaint of the user in not solved by technician within 24 hours.
i am able to send mail to administrator
i just want a watch on database for unsolved issues with timespan of more than 24 hours and inform to administrator about the same
I maintain a ASP.NET web application that causes a user's network connection to reset for several seconds when it executes a procedure. Therefore, the page request times out on the user's end as they never receive the web application's response (the connection dies before it gets the response packet).
To resolve this situation, I was contemplating having the ASP.NET page execute an asynchronous function that incorporates a Thread.Sleep(5000); // sleep for 5 seconds before executing the connection reset This way, the browser has 5 seconds to receive the page's response before their connection resets.
I have concerns with using Thread.Sleep and asynchronous functions in ASP.NET though. I've never attempted to do it before, so I'm unsure of the potential problems it may cause. Does anyone see potential problems with starting an asynchronous thread that contains a Thread.Sleep in an ASP.NET application?
I don't know if it's IIS, ASP.NET or IIS7 related. I take a chance here, if you think I'm in the wrong forum, just tell me which one I should post to.
I have made the smallest demo project to illustrate my problem. You can download the sources
Here
Visual Studio 2008, .NET 3.5, IIS7, Windows 7 Ultimate 32 bits. The IIS Website is configured ONLY for Windows Authentication in an Integreated pipeline app pool (DefaultAppPool).
Here's the problem. I have an Asp.NET MVC 2 application. In an action, I start a thread. The View returns.
The thread is doing it's job... but it needs to access Thread.CurrentPrincipal.Identity.Name
BANG
The worker process of IIS7 stops. I have a window that says: "Visual Studio Just-In-Time Debugger An unhandled exception ('System.Object.DisposedException') occured in w3wp.exe [5524]"
I checked with the debugger and the Thread.CurrentPrincipal.Identity is valid, but the Name property is disposed.
If I put a long wait in the action before it returns the view, then the Thread can do it's job and the Identity.Name is not disposed. So I think the Name gets disposed when the view is returned.
For the sake of the discussion, here's the code that the thread runs (but you can also download the demo project. The link is on top of this post):
I'm new to threading and have used it successfully, but limited. I can spawn a thread and have the main thread reference variables in the spawned thread, but I don't know how to allow the spawned thread to reference (and update) variables in the main thread.
Any example threading code I've seen on the web appears to be WAY more complicated than what I do, so I am unable to understand or integrate into my code.
I want to start a new thread to query a database while my web application continues running. I was under the impression that by using threads I can run the querying process independently while the normal web application page cycle carries on, but I could be wrong.
public class DbAsyncQuery { Dictionary<string, object> serviceResults = new Dictionary<string, object>(); public void UpdateBillingDB() { QueryAllServices(); foreach (KeyValuePair<string, object> p in serviceResults) { IEnumerable results = (IEnumerable)p.Value; IEnumerable<object> sessions = results.Cast<object>(); DbUtil.MakeBillingDBEntry(sessions, p.Key); } } public static string[] servicesToQuery = new string[] // Must go in config file ultimately { "xxx.x.xxx.xx" }; public delegate void Worker(); private Thread worker; public void InitializeThread(Worker wrk) { worker = new Thread(new ThreadStart(wrk)); worker.Start(); } public void InitializeQuery() { Worker worker = QueryAllServices; InitializeThread(worker); } private void QueryAllServices() { Dictionary<string, DateTime> lastEntries = DbUtil.GetLastEntries(); foreach (string ip in servicesToQuery) { string fullServicePath = "http://" + ip + ":800/MyWebService.asmx"; //object[] lastEntry = new object[] { lastEntries[ip] }; object[] lastEntry = new object[] { new DateTime(2011, 1, 1, 0, 0, 0) }; object obj = WebServiceHandler.CallWebService (fullServicePath, "MyWebService", "GetBillingDBEntries", lastEntry); serviceResults.Add(ip, obj); } } }
It seems to basically stall and wait to finish the query before loading the page (which can be thousands of rows, so it takes awhile). I put this in the following section of Global.asax:
This is one of my first web pages, and I'm new to threading. I understand there is a difference between creating your own thread and using the ThreadPool. In this method, I am using my own thread, I think. Not sure if that's the best way. The querying process can be completely independent, and its only going to occur on scheduled intervals (every 8 hours or so). The user doesn't need to have up to the minute data, so it can take awhile. I just don't want the site to wait for it to finish, if that's possible.
lock (this) { if (!isGoodPassword) Thread.Sleep(2000); } I would expect that this would allow all correct passwords without stalling, but if one user enters a bad password another successful password from a different user would also be blocked. However, the lock doesn't seem to lock across ASP.NET threads.
I want a example of multithreading .i want to use it in a web form not on console.i am using C#.net .and how to use thread.sleep method for a particular thread.
I there I have recently created an ASP website wich uses .net 4 and SQL db but soem some reason even displaying 20 records in a gridview is slow... So after some reading I converted the website to a Web Application Project so its compile prior to publish.. But yet again this is a bit slow. pages loading time is not of a bit issue...
I need little clarification regarding the Application Domain. As it has been said in the .net framework documentation "a process can have one or more application domain", Does it means There can be only one process in a machine dedicated for the .net application and whenever a new .net application gets executed, an application domain gets created in the above mentioned process?
I have developed web application using asp.net 3.5 ,c# 3.0 and visual studio 2008,sql server 2005. i have created .msi file to deploy application on server.. now for testing purpose running in lan for that i want give url name eg.now i'm accessing from LAN like this
I'm going to publish an asp.net pre-compiled web site on shared hosting account but I don't want my code to be copied and able to run on another domain. I need to check domain and if not example.com or www.example.com redirect to error page or show error as response.
EDIT: Here is my solution based on given answers
void Application_BeginRequest(object sender, EventArgs e) { string[] safeDomains = new string[] { "localhost", "example.com", "www.example.com" }; if (!((IList)safeDomains).Contains(Request.ServerVariables["SERVER_NAME"])) { Response.Write("Domain not allowed!"); Response.End(); } }