How can I able to stop the execution of my method when I click a button?
public void ForEach()
{
CreateFolders();
//For each process get the equivalent processcode
foreach (string item in Processes)
{
ItemValue = item;
//Get process code for the process under the selected source
GetActiveProcess();
#region Switch
switch (ProcessCode)
{
#region DownloadFile
case "Download File":
ForDownloadFile();
break;
#endregion
#region UnzipFile
case "Unzip File":
ForUnzipFile();
break;
#endregion
#region RenameFile
case "Rename File":
ForRenameFile();
break;
#endregion
#region MergeFile
case "Merge File":
ForMergeFile();
break;
#endregion
#region ZipFile
case "Zip File":
ForZipFile();
break;
#endregion
#region UploadFile
case "Upload File":
ForUploadFile();
break;
#endregion
}
#endregion
}
}
How can I end my public void foreach when I click the stop button. I would like to stop the downloading, or extracting of file etc when ever I click on stop without closing my application.
I've tried using return but it continues to execute (Download/ extract etc).