Hi @윤수 장 , Welcome to Microsoft Q&A,
In a single-threaded environment, when methods are linked to a delegate and executed, the order of execution is guaranteed. A delegate is a type used in the .NET Framework to reference methods. It can contain references to one or more methods.
When you call a delegate, the delegate executes the methods in the order they are added to the delegate. This order of execution is guaranteed even in a single-threaded environment. This is because the delegate internally maintains a list of methods and executes them in the order they are added.
For example, consider the following C# code:
using System;
class Program
{
//Define a delegate
delegate void MyDelegate();
static void Main()
{
MyDelegate myDelegate = null;
//Add method to delegate
myDelegate += Method1;
myDelegate += Method2;
myDelegate += Method3;
// Call the delegate and execute the methods in the order they were added.
myDelegate();
Console.ReadLine();
}
static void Method1()
{
Console.WriteLine("Method1");
}
static void Method2()
{
Console.WriteLine("Method2");
}
static void Method3()
{
Console.WriteLine("Method3");
}
}
In this example, Method1, Method2, and Method3 are executed in the order in which they are added to the delegate. The order of execution is predictable and not affected by single-threaded environments.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.