Web Forms :: Kill Current Running Process - To Run New?
Mar 12, 2010
Is it possible to kill the current running process in order to run a new process in asp.net? The problem I have is that when a report is running, the user may click on other process, then the process of report should be finished in order to run another process. So is it possible to kill the current process?
I have an asp.net application, which opens an excel file and reads it content. If user closes the application or the page when the excel file reading in progress, i want to kill the Excel process (which is opened by the current instance.
i am using icrosoft.Office.Interop.Excel to read the excel file datas. i need to kill the "EXCEL" process if any runtime error occur or any other "EXCEL" process running before read the excel data. I am using this code to kill the process.
private void KillProcess(string processName) { system.Diagnostics.Process myproc = new System.Diagnostics.Process(); //Get all instances of proc that are open, attempt to close them. try { foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcessesByName(processName)) { if (!thisproc.CloseMainWindow()) { //If closing is not successful or no desktop window handle, then force termination. thisproc.Kill(); } } // next proc } catch (Exception Exc) { throw Exc; } }
Now, My question is if the multiple users running the web application with different sessions then it cause problem right. because this method close all the "Excel" process that are currently running. how to kill the excel process for the particular session.
I know that similar questions have been asked all over the place, but I'm having trouble finding one that relates directly to what I'm after.
I have a website where a user uploads a data file, then that file is transformed and imported into SQL. The file could be up to 50mb in size, and some times this process can take 30 minutes or sometimes even longer.
I realise I need to palm off the actual work to another process, and poll that process on the web page. I'm wondering what the best approach would be though? Being a web developer by trade, I'm finding all this new Windows Service stuff a bit confusing, and I just wanted somewhere to start.
So:
Can I do / should I being doing this with a windows service? if so, how?
Should I use WCF? If this runs under IIS, will I have problems with aspnet_wp.exe recycling and timing out my process?
clarifications
The data is imported into sql, there's no file distribution taking place.
If there is a failure, it absolutely MUST be reported to the user. The web page will poll every, lets say, 5 seconds, from the time the async task begins, to get the 'status' of the import. Once it's finished another response will tell the page to stop polling for status updates.
queries on final decision
ok, so as I thought, it seems that a windows service is the best idea. So as to HOW to get it to work, it seems the 'put the file there and wait for the service to pick it up' idea is the generally accepted way, is there a way I can start a process run by the service, without it having to constantly be checking a database table / folder? As I said earlier, I don't have any experience with Windows Services - I wondered if I put a public method in the service, can I call it somehow?
We need assistance with a portion of a major web application project scheduled to begin user testing within 10 days. The troublesome part of the code calls an external application when a button is clicked in Web page. When run from a command prompt or bat file, the external application, App.exe, runs perfectly producing the desired result. We created a test page and a small console application, Con.exe, to test the button code with a known quantity. The test application runs perfectly when the button in the Web page is clicked. However when we change the code to run App.exe instead of Con.exe, the App.exe code will not execute. We even tried creating a bat file to execute App.exe. Like the exe, the bat file executes from the command prompt or when double-clicked,but fails to run when called as a process from the button click event. Can anyone assist us? Here is the C# code: (.Net 3.5 sp1)
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Diagnostics; namespace WebButtonTest public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { protected void Timer1_Tick(object sender, EventArgs e) { int checkNumber = 0; if (Session["checkNumber"] != null).......
I'm in a need to get a list of all the ASP.NET running worker process and its associated application pools and process ID.Is there a way to do this pragmatically (C#) or a powershell script?
In an asp.net web form, I keep getting a connection reset error message. The page is doing a some long running processing (about 2-5 minutes).
I have no problem when the web request comes from the same machine as the web server. But when the request originates across the network, I get a connection reset error about 1:30 or 2 minutes into waiting for a response.
I have set the in web.config for this application and put the application it's own application pool.
What else can I try?
Edit
The purpose of this page is to accept input from the user, calculate something, and send the result back to them. The long running calculation isn't something I can offload until a later time.
I want to be able to run an ASP.NET application when a file is upload via FTP. I understand how to use the filewatcher class to monitor the directory but I don't know where to put the code so it is always running.
Files will be uploaded once per month for each group of users of the system and the next time the user logs on after the upload I would like the application to reflect the new data. I don't want to check for a new upload when each user logs on because the processing could take a log time.
The uploads are automatic from multiple other computer systems and not done by any user.
The Application is hosted (by GoDaddy) so I don't have full control of the server.
Is there any way to have a process running all the time in the background and if so how? The application is written in VB.net.
Note:- i don't want to use updateprogress etc. control of ajax
on button click, long task(e.g thread) runs in my webpage for about 4-5 minutes.I want to show status to user either by a processing image through javascript(image must be shown in a certain part of page other part of page will remain intact) or an exact status of process if possible. i have tried a lot but all in vein.
Situation:I have an ASP .NET application that will search through docs using Lucene. I want to run the initial indexing (the index will be incremental after the initial run so there wont be need to index the whole directory again in future). Currently, I have about 5GB of docs (45000files).Problem: My application times out before completing the process. I have altered the TimeOut like this:HttpContext.Current.Server.ScriptTimeout = 200000;but it still does not complete the process.
My web application currently requires users to upload files, after which I take it for "further processing". This processing is VERY time consuming and can take a while before the control gets back to the user. I would like to run this in the background and not have the user wait until this completes.
I know this question has been asked in this very forum before but I'm not able to understand or I'm not able to proceed in the right direction. My understanding is there are a few ways I can go about this
a) create a BackgroundWorker process in my Global.asax file that will spawn a process and take care of the activity.
b) create a web service that will do the processing for me .. (how?)
I've been having a difficult time with this. I have an asp.net page. The user hits the "Run" button and I have code IN AN ASSEMBLY, not in the APP_CODE folder that is called and runs a long process that moves product info from a file into the database. While the user waits, I would like them to see status updates like what product the import process in on and status info. I'm assuming I'd break off into another thread and use Ajax but I have no idea how to do this.
Wondering if there is a performance difference between letting a long running process hang in asp.net vs running the process via a windows service. I have done this once before and the windows service was much quicker and didnt bog down my system, whereas the asp.net request seemed to wreak havoc.
I have a solution that was originally created using VS 2008. I have quite a few unit tests that all passed when ran in VS 2008.
Yesterday I opened this solution in VS 2010 and converted it using the wizard. The solution built just fine, it runs just fine, BUT now all tests that access the db fail. I get the same error on every test (below).
"The runtime has encountered a fatal error. The address of the error was at 0x5b3b5ad7, on thread 0x19a4. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack."
In test classes that use ClassInitialize() and ClassCleanup() methods, all the tests fail. All tests fail with the same error, "The agent process was stopped while the test was running." Tests in test classes that do not utilize ClassInitialize() and ClassCleanup() (these tests do not hit the database) all pass.
When this was a VS2008 project all 153 tests passed. No changes have been made to these tests, other than converting the project to a VS2010 project.
I've been playing around with one test class. I commented out the ClassInitialize() and ClassCleanup() methods. I rewrote one test method and mocked everything. I tried running just that one test. I still got the "The agent process was stopped while the test was running" error.
Visual Studio 2010, version 10.0.30319.1 RTMRel
Test framework: integrated VS 2010 MS Test
Mocking framework: Not using mocking, I have a db that is destroyed and recreated in MyClassInitialize(), it is populated with known values. Yes, I know I should be using mocking, but this is an older app and it has not been updated with all of the new bells and whistles yet.
DB Framework: NHibernate
Target Framework is 3.5 for all projects in this solution except for the test project. The target framework is 4.0 for the test project. I tried changing it to 3.5, it will not let me.
"Attempted re-targeting of the project has been canceled. You cannot change the specified .NET framework or profile for a test project."
Bit of a long shot, but is there a way in ASP.NET to dynamically get the website's URL [URL] when there is no HttpContext.Current available.
There is no HttpContext because the code is running in a background thread* (but under the ASP.NET AppDomain). I have a background process that sends emails out every evening, and needs to include the Web address, but I don't want to hard code it because of deployments and testing (it changes from [URL] to[URL] and then to [URL] for the live site).
I've developed a popup email .aspx used on our intranet based web app that is auto generated with .pdf's attached. I'm developing with VS 2008 ASP.Net 3.5 C# and System.Net.Mail.MailMessage. I can create and send the email with no issues. The problem is with any attempt to open or delete the attachments I get the above error. The .pdf's a copied with the following code:
FileStream fsr = new FileStream(inFilename, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader reader = new BinaryReader(fsr); byte[] bytes = new byte[fsr.Length]; reader.Read(bytes, 0, bytes.Length); FileStream fsw = new FileStream(outFileName, FileMode.Create, FileAccess.Write, FileShare.Write); BinaryWriter writer = new BinaryWriter(fsw); writer.Write(bytes, 0, bytes.Length); // clean up writer.Flush(); writer.Close(); writer = null; fsw.Close(); fsw.Dispose(); fsw = null; reader.Close(); reader = null; fsr.Close(); fsr.Dispose(); fsr = null; Later after sending the email I: mailMessage.Dispose(); mailMessage = null; foreach (string fileName in attachments) { if (File.Exists(fileName)) File.Delete(fileName); }
The error occurs at: the File.Delete(fileName);
how I can delete or reopen these files after sending the email?
I have an application that I use to run Exchange Powershell commands inside C# code like below. This is an example of the relevant lines I use to run the powershell command.
This code works perfect in all cases until now. the script I am trying to run instead of the one above is to set the RetentionPolicy for a mailbox. The script I am trying to run looks like this: Set-Mailbox -Identity 'rj' -RetentionPolicy 'Main Campus Retention Policy' When I run this in powershell itself it works perfectly but when I try to run it using the code below I get the error, "Cannot invoke this function because the current host does not implement it."
From this error, it almost seems like the command that runs in C# cannot run the RetentionPolicy command but that doesn't make much sense. I have Googled this and tried everything suggested but no luck.
My code is that I want to create a log file and log it upon a new user browsing the site. However, what i did was I put in a 6 second delay and then used another browser to access the page. And it threw an Exception saying it is being used by another process which is true. So how come I set it so that, if IT is being used by another process, WAIT and retry every 500 milliseconds until it becomes free/available?
here's the code:
protected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) // if this is the first time page loads, set k to 1 { lognewuser(); }}
I am logged in as the administrator when I installed an application named pdflatex.exe on my server. This application works as a converter from LaTeX input file to Pdf file. I host an Asp.net MVC 3 application running under an Application Pool Identity with Load User Profile = True. The Asp.net MVC 3 code contains a code that executes pdflatex.exe using System.Diagnostic.Process instance as follows:
Process p = new Process(); p.EnableRaisingEvents = true; p.Exited += new EventHandler(p_Exited); p.StartInfo.Arguments = "-interaction=nonstopmode " + inputpath; p.StartInfo.WorkingDirectory = @"c:mydomain.comworking"; p.StartInfo.UseShellExecute = false; p.StartInfo.FileName = "pdflatex.exe"; p.Start(); p.WaitForExit();
From the scenario above, the web application runs under a restricted acount but it executes an external application under a default account that I don't know. Can an application running under a less privileged account start a process executing another application under an administrative account?
I have a Gridview that displays a huge list of products. On Client click of a select button in the grid I fill textboxes with the selected row's data. When i do this, I want to stop the Grid from Binding in Javascript. Is this a possible feat? Now the Gridview is in an updatepanel. Perhaps i could stop it from updating???
My javascript code is calling a asp.net webservice, so i have a call to the webservice something like this:MyWebservice.GetData(param, ResponseReceived, ResponseTimeOut, ResponseError);When the webservice returns data, ResponseReceived method is called.However sometimes the user might navigate to another url before the webservice call actually returns, in such a scenario FireFox throws an Error saying 'An error occured oricessubg the request. The server method GetData failed'So my question is how can i kill the async call when the user navigates to another page or makes another request to the webservice? I know in a normal XMLHttpRequest i could have called Abort method, but not sure how to make it work with the above webservice proxy.