Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
.NET Framework
Classe Semaphore e Thread.CurrentThread.ManagedThreadId
domenica 11 luglio 2010 - 00.11
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
cosmopsis
Profilo
| Junior Member
74
messaggi | Data Invio:
dom 11 lug 2010 - 00:11
Sto iniziando a studiare il threading. Per la classe Semaphore ho questo codice di esempio:
static void Main(string[] args) {
Semaphore mySemaphore = null;
const int kMaxNum = 5;
try {
mySemaphore = Semaphore.OpenExisting("MYSEMAPHORE");
} catch (WaitHandleCannotBeOpenedException) {
//impossibile aprire perché non esiste
if (mySemaphore == null){
mySemaphore = new Semaphore(0, 4, "MYSEMAPHORE");
for (int i = 1; i <= kMaxNum; i++) {
Thread t = new Thread(new ParameterizedThreadStart(exampleFunction));
t.Start(mySemaphore);
}
Thread.Sleep(500);
mySemaphore.Release(kMaxNum - 1);
}
}
}
static void exampleFunction(object i) {
Console.WriteLine("{0} - {1}", Thread.CurrentThread.ManagedThreadId, i);
}
L'output è:
3 - System.Threading.Semaphore <===
4 - System.Threading.Semaphore
5 - System.Threading.Semaphore
6 - System.Threading.Semaphore
7 - System.Threading.Semaphore
Mi spieghereste perchè il ManagedThreadId parte sempre da 3?
grazie
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !