简体   繁体   中英

How to run multiple instance of WinForms application

I have developed a WinForms application for two purposes

1) It has a form which will accept configuration from user and store it

2) Based on configuration values entered in step 1. a task scheduler will be created that will transfer files from local folder to FTP

Now, when task is running from scheduler and at the same time if i open a form it will give me error like

Process/exe is already in use. Cannot start new instance.

Is it possible to open form in different instance to that of scheduler task?

[STAThread]
static void Main(string[] args)
{

if (args.Length > 0 && args[0] == "AutoRun")
{
Logger.Info("Auto run successfull.");
GetConfigValues getConfigValues = new GetConfigValues();
UploadToFTP uploadToFTP = new UploadToFTP();
string result = uploadToFTP.UploadFile(getConfigValues.LocalPath, getConfigValues.FTPServer, getConfigValues.FTPFolderPath, getConfigValues.FTPUsername, getConfigValues.FTPPassword);
}
else
{
Logger.Info("Manual run successfull.");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
    }
}

Assuming this is related to Task Scheduler and not your application specifically:

You can configure the behaviour of the Task Scheduler task when the target process is already running. In the UI, this is on the Settings tab, "If the task is already running...". The default is "Do not start a new instance"; what you want is probably "Run a new instance in parallel", though a better option would probably be to have a different executable for handling the background tasks, and queuing the consecutive runs instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM