Dear expert
Thank for your support
The main script have command line. If I use return key, I have to use it many times in main script.
Is there any way to stop main script from other script?
Best
To ensure the integrity of the system, the .NET Framework does not provide a direct way to stop a thread. Instead, threads should be programmed to periodically check a condition that indicates whether execution should be interrupted, such as a control variable or an event. When the condition is met, the thread can exit the loop or terminate execution appropriately.
You can use as an example the code below, it will check periodically if the trigger tag is equal to 1, if not , the thread will keep running.
We noticed that you are facing an error which may be due to the absence of a method called “exit”. You said you want to avoid writing repetitive code, so we suggest reusing code using methods, and we found a helpful link at:
This is a C# code that defines a function called Main(). The Main() function contains a loop that will run five times, from i = 1 to i < 6. Within the loop, there is a conditional statement that checks whether the exit() function returns true when passed the current value of i.
The exit() function takes an integer argument i and returns a boolean value based on whether i is equal to 3. If i is equal to 3, the function returns true; otherwise, it returns false.
If the exit() function returns true for the current value of i, the return statement inside the conditional statement will immediately exit the Main() function, causing the loop to stop executing and the program to terminate.
public void Main()
{
for (int i = 1; i < 6; i++)
{
//Put your code here
if (exit(i))
{
return;
}
}
}
public bool exit(int i)
{
return i == 3;
}
Please inform us if you have comprehended this explanation. If you require further clarification or additional examples, do not hesitate to let us know, and we will gladly provide them.