Je crée une application de console, dans laquelle j'ai besoin d'appeler une méthode, qui fera une liste de tâches. Mais je veux que cette méthode n'a aucun impact sur l'application principale, elle fera juste ses travaux .. c'est tout..net C#: Création d'un processus asynchrone
5
A
Répondre
1
Jetez un oeil à this article.
Exemple:
using System;
using System.Threading;
public class ServerClass
{
// The method that will be called when the thread is started.
public void InstanceMethod()
{
Console.WriteLine(
"ServerClass.InstanceMethod is running on another thread.");
// Pause for a moment to provide a delay to make
// threads more apparent.
Thread.Sleep(3000);
Console.WriteLine(
"The instance method called by the worker thread has ended.");
}
public static void StaticMethod()
{
Console.WriteLine(
"ServerClass.StaticMethod is running on another thread.");
// Pause for a moment to provide a delay to make
// threads more apparent.
Thread.Sleep(5000);
Console.WriteLine(
"The static method called by the worker thread has ended.");
}
}
public class Simple{
public static int Main(String[] args)
{
Console.WriteLine("Thread Simple Sample");
ServerClass serverObject = new ServerClass();
// Create the thread object, passing in the
// serverObject.InstanceMethod method using a
// ThreadStart delegate.
Thread InstanceCaller = new Thread(
new ThreadStart(serverObject.InstanceMethod));
// Start the thread.
InstanceCaller.Start();
Console.WriteLine("The Main() thread calls this after "
+ "starting the new InstanceCaller thread.");
// Create the thread object, passing in the
// serverObject.StaticMethod method using a
// ThreadStart delegate.
Thread StaticCaller = new Thread(
new ThreadStart(ServerClass.StaticMethod));
// Start the thread.
StaticCaller.Start();
Console.WriteLine("The Main() thread calls this after "
+ "starting the new StaticCaller thread.");
return 0;
}
}
1
Questions connexes
- 1. création de processus
- 2. Exemples d'interaction asynchrone dans C# .Net?
- 3. Appel asynchrone C# .Net débutants question
- 4. XmlReader asynchrone dans .NET?
- 5. Création d'une méthode d'extension asynchrone
- 6. Exécuter le processus dans .NET et C++
- 7. C# .net Get FullName de processus ID
- 8. Processus Storec asynchrone sans attendre la fin
- 9. exécution asynchrone Sql dans .NET
- 10. Création d'un processus interactif
- 11. Déclenchement de processus/création de processus Linux
- 12. Création d'un processus inter-processus EventWaitHandle
- 13. Comment utiliser HttpWebRequest (.NET) de manière asynchrone?
- 14. Création d'un processus sans élévation
- 15. .NET inter-processus "événements"
- 16. Création d'une application C# .net Windows extensible
- 17. C++ programmation réseau asynchrone
- 18. C# socket asynchrone BeginSend
- 19. transmission série asynchrone C
- 20. Démarrer le processus asynchrone et attendre qu'il se termine
- 21. Création de plusieurs processus et simulation en C via fork()
- 22. Création de processus à distance C# WMI -GUI Hack
- 23. Création EPUB dans .Net
- 24. Question sur la programmation asynchrone, enfilage .net
- 25. .NET LINQ to SQL commit asynchrone
- 26. E/S de fichier asynchrone dans .NET
- 27. Rx dans .Net 3.5 non asynchrone?
- 28. Écoute asynchrone sur la classe qui a lancé le processus asynchrone
- 29. C# problème de socket asynchrone
- 30. Demande http asynchrone Objective-C
Et qu'est-ce que ces emplois ressemblent? Des données partagées? –