Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a console application (exe assembly) which i need to set up as a scheduled task.

based on passed arguements in main method, It performs two different functions. 

I have set up two job name pointing to the same exe and each has got its own arguements.

what do i do to make it run simultaneously at the same time?


What I have tried:

static void Main(string[] args)
{
 if (args.Length > 0)
                {
                    if (args[0].Trim().ToLower() =="excel")
                    {
                       CreateExcelFile();
                    }
                }
                else
                {
				CreatePdfFile();
				}
}
Posted
Updated 25-Feb-19 6:08am
Comments
Richard MacCutchan 22-Feb-19 4:26am    
There is no problem doing this, you can run as many copies of the same application at the same time as you like; subject of course to system resource limits.
Richard Deeming 22-Feb-19 11:06am    
We can't see what your code is doing. But based on the function names, I'm going to guess that you're using Office Interop, which won't work from a scheduled task.

Considerations for server-side Automation of Office[^]
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."

Scheduled tasks count as unattended non-interactive applications.

There are various ways to create Excel spreadsheets without using Office interop. For example:
* EPPlus[^];
* ClosedXML[^];
* The OpenXML SDK[^];
istudent 25-Feb-19 8:53am    
I am using EPPlus Lib to create excel file.
istudent 25-Feb-19 9:00am    
I have used same file to write log details
istudent 25-Feb-19 9:05am    
In Last Run Result I get error code 0xC00000FD to the one(excel) where I have passed argument 'excel'. but the other task run successfully. I have set both to trigger to run at the same time.

Your problem description isn't clear at all.

In Task Scheduler, you can schedule as many tasks as you want and they can be executed at the same time. You just set the time in the task when you want it to execute. There's nothing that says you can only have one task running at a time.

In your case, you setup two scheduled tasks, each with the same executable, but different parameters depending on what you want that instance to do.
 
Share this answer
 
Comments
istudent 22-Feb-19 1:13am    
I have an executible, say my app.exe, I want to run this one exe at the same time and do two task simultaneously. I created two tasks, named them excel task with arg and pdf task without arg and point to the same exe and set to triggered in couple of seconds difference. But pdf run successfully but other couldn't with error code 0xc00000bf I am not sure if it's bf to be exact right now. Is it due to main being static method, it's not letting to run two instances of same exe?
Dave Kreskowiak 22-Feb-19 8:51am    
This is going to be a problem with your code, not with the scheduler or running two instances of your app at once.

0xc00000bf means "Bad Network Path", so... since we know nothing of what your code is doing, and how its trying to do it, there's really not much anyone can tell you.

So, what is your code doing that involves network paths?
istudent 25-Feb-19 9:16am    
Sorry, error code is 0xC00000FD
Dave Kreskowiak 25-Feb-19 10:13am    
0xC00000FD should be "stack overflow". There is something wrong in your code but since we can't see you're code and know nothing about it, it's impossible to tell you what's wrong.
istudent 25-Feb-19 10:50am    
background of the app is, We had this app to write pdf files.
Now we need to add functionailty to add excel files also for other department.
Pdf file creation in once in a week while excel file is on daily basis.

So, i changed the app so that if arg 'excel' has passed do excel file createion
and passed the arg while i set up the job and trigger it to run daily.

Doing so, I did not have to update the old job which has been creating pdf as we never had passed any arguement
while setting that job.

One thing is that, both writes in the same log file.

Is it due to that, when both run at the same time, both tries to write at the same time into the same file?

I found out the cause for the error while triggering the exe at the same. Both job trying to use the same log file to write the log. I separated the log Files for each job. Now it does not throw any error.

Thank you guys for reaching out and helping me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900