J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques
secondes a se lancer, pendant se temps je voudrais afficher
un autre formulaire (Form2) pour faire patienter l'utilisateur.
Tout marche bien, sauf que le formulaire (form2) pour patienter
n'affiche pas le contenu que j'ai prévu, mais reste genre
transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement
en attendant le traitement du form1 ?
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Sébastien
Bonjour,
Tu dois lancer l'execution de ta Form2 dans un thread
voici un exemple de code :
Imports System Imports System.Threading
' Simple threading scenario: Start a Shared method running ' on a second thread. Public Class ThreadExample ' The ThreadProc method is called when the thread starts. ' It loops ten times, writing to the console and yielding ' the rest of its time slice each time, and then ends. Public Shared Sub ThreadProc() Dim i As Integer For i = 0 To 9 Console.WriteLine("ThreadProc: {0}", i) ' Yield the rest of the time slice. Thread.Sleep(0) Next End Sub
Public Shared Sub Main() Console.WriteLine("Main thread: Start a second thread.") ' The constructor for the Thread class requires a ThreadStart ' delegate. The Visual Basic AddressOf operator creates this ' delegate for you. Dim t As New Thread(AddressOf ThreadProc) ' Start ThreadProc. On a uniprocessor, the thread does not get ' any processor time until the main thread yields. Uncomment ' the Thread.Sleep that follows t.Start() to see the difference. t.Start() 'Thread.Sleep(0)
Dim i As Integer For i = 1 To 4 Console.WriteLine("Main thread: Do some work.") Thread.Sleep(0) Next
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.") t.Join() Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.") Console.ReadLine() End Sub End Class
"pascal" a écrit dans le message de news:
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques secondes a se lancer, pendant se temps je voudrais afficher un autre formulaire (Form2) pour faire patienter l'utilisateur. Tout marche bien, sauf que le formulaire (form2) pour patienter n'affiche pas le contenu que j'ai prévu, mais reste genre transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement en attendant le traitement du form1 ?
Merci pour vos réponse
Pascal
Bonjour,
Tu dois lancer l'execution de ta Form2 dans un thread
voici un exemple de code :
Imports System
Imports System.Threading
' Simple threading scenario: Start a Shared method running
' on a second thread.
Public Class ThreadExample
' The ThreadProc method is called when the thread starts.
' It loops ten times, writing to the console and yielding
' the rest of its time slice each time, and then ends.
Public Shared Sub ThreadProc()
Dim i As Integer
For i = 0 To 9
Console.WriteLine("ThreadProc: {0}", i)
' Yield the rest of the time slice.
Thread.Sleep(0)
Next
End Sub
Public Shared Sub Main()
Console.WriteLine("Main thread: Start a second thread.")
' The constructor for the Thread class requires a ThreadStart
' delegate. The Visual Basic AddressOf operator creates this
' delegate for you.
Dim t As New Thread(AddressOf ThreadProc)
' Start ThreadProc. On a uniprocessor, the thread does not get
' any processor time until the main thread yields. Uncomment
' the Thread.Sleep that follows t.Start() to see the difference.
t.Start()
'Thread.Sleep(0)
Dim i As Integer
For i = 1 To 4
Console.WriteLine("Main thread: Do some work.")
Thread.Sleep(0)
Next
Console.WriteLine("Main thread: Call Join(), to wait until
ThreadProc ends.")
t.Join()
Console.WriteLine("Main thread: ThreadProc.Join has returned. Press
Enter to end program.")
Console.ReadLine()
End Sub
End Class
"pascal" <scalefs@hotmail.com> a écrit dans le message de
news:3c244cee.0411090635.2127ae9b@posting.google.com...
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques
secondes a se lancer, pendant se temps je voudrais afficher
un autre formulaire (Form2) pour faire patienter l'utilisateur.
Tout marche bien, sauf que le formulaire (form2) pour patienter
n'affiche pas le contenu que j'ai prévu, mais reste genre
transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement
en attendant le traitement du form1 ?
Tu dois lancer l'execution de ta Form2 dans un thread
voici un exemple de code :
Imports System Imports System.Threading
' Simple threading scenario: Start a Shared method running ' on a second thread. Public Class ThreadExample ' The ThreadProc method is called when the thread starts. ' It loops ten times, writing to the console and yielding ' the rest of its time slice each time, and then ends. Public Shared Sub ThreadProc() Dim i As Integer For i = 0 To 9 Console.WriteLine("ThreadProc: {0}", i) ' Yield the rest of the time slice. Thread.Sleep(0) Next End Sub
Public Shared Sub Main() Console.WriteLine("Main thread: Start a second thread.") ' The constructor for the Thread class requires a ThreadStart ' delegate. The Visual Basic AddressOf operator creates this ' delegate for you. Dim t As New Thread(AddressOf ThreadProc) ' Start ThreadProc. On a uniprocessor, the thread does not get ' any processor time until the main thread yields. Uncomment ' the Thread.Sleep that follows t.Start() to see the difference. t.Start() 'Thread.Sleep(0)
Dim i As Integer For i = 1 To 4 Console.WriteLine("Main thread: Do some work.") Thread.Sleep(0) Next
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.") t.Join() Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.") Console.ReadLine() End Sub End Class
"pascal" a écrit dans le message de news:
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques secondes a se lancer, pendant se temps je voudrais afficher un autre formulaire (Form2) pour faire patienter l'utilisateur. Tout marche bien, sauf que le formulaire (form2) pour patienter n'affiche pas le contenu que j'ai prévu, mais reste genre transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement en attendant le traitement du form1 ?
Merci pour vos réponse
Pascal
Eric Vernié [MS]
Bonjour Sébastien
L'utilisation des threads est élégante, mais tu peux également utiliser plus simplement l'instruction Application.DoEvents Module Module1 Sub Main() Dim f As New Form2 f.Show() Application.DoEvents() Application.Run(New Form1) End Sub End Module
Eric Vernié Microsoft France
"Sébastien" a écrit dans le message de news:
Bonjour,
Tu dois lancer l'execution de ta Form2 dans un thread
voici un exemple de code :
Imports System Imports System.Threading
' Simple threading scenario: Start a Shared method running ' on a second thread. Public Class ThreadExample ' The ThreadProc method is called when the thread starts. ' It loops ten times, writing to the console and yielding ' the rest of its time slice each time, and then ends. Public Shared Sub ThreadProc() Dim i As Integer For i = 0 To 9 Console.WriteLine("ThreadProc: {0}", i) ' Yield the rest of the time slice. Thread.Sleep(0) Next End Sub
Public Shared Sub Main() Console.WriteLine("Main thread: Start a second thread.") ' The constructor for the Thread class requires a ThreadStart ' delegate. The Visual Basic AddressOf operator creates this ' delegate for you. Dim t As New Thread(AddressOf ThreadProc) ' Start ThreadProc. On a uniprocessor, the thread does not get ' any processor time until the main thread yields. Uncomment ' the Thread.Sleep that follows t.Start() to see the difference. t.Start() 'Thread.Sleep(0)
Dim i As Integer For i = 1 To 4 Console.WriteLine("Main thread: Do some work.") Thread.Sleep(0) Next
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.") t.Join() Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.") Console.ReadLine() End Sub End Class
"pascal" a écrit dans le message de news:
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques secondes a se lancer, pendant se temps je voudrais afficher un autre formulaire (Form2) pour faire patienter l'utilisateur. Tout marche bien, sauf que le formulaire (form2) pour patienter n'affiche pas le contenu que j'ai prévu, mais reste genre transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement en attendant le traitement du form1 ?
Merci pour vos réponse
Pascal
Bonjour Sébastien
L'utilisation des threads est élégante, mais tu peux également utiliser plus
simplement l'instruction Application.DoEvents
Module Module1
Sub Main()
Dim f As New Form2
f.Show()
Application.DoEvents()
Application.Run(New Form1)
End Sub
End Module
Eric Vernié
Microsoft France
"Sébastien" <sbeaux@gfi.fr> a écrit dans le message de news:
u9PPj3pxEHA.1392@tk2msftngp13.phx.gbl...
Bonjour,
Tu dois lancer l'execution de ta Form2 dans un thread
voici un exemple de code :
Imports System
Imports System.Threading
' Simple threading scenario: Start a Shared method running
' on a second thread.
Public Class ThreadExample
' The ThreadProc method is called when the thread starts.
' It loops ten times, writing to the console and yielding
' the rest of its time slice each time, and then ends.
Public Shared Sub ThreadProc()
Dim i As Integer
For i = 0 To 9
Console.WriteLine("ThreadProc: {0}", i)
' Yield the rest of the time slice.
Thread.Sleep(0)
Next
End Sub
Public Shared Sub Main()
Console.WriteLine("Main thread: Start a second thread.")
' The constructor for the Thread class requires a ThreadStart
' delegate. The Visual Basic AddressOf operator creates this
' delegate for you.
Dim t As New Thread(AddressOf ThreadProc)
' Start ThreadProc. On a uniprocessor, the thread does not get
' any processor time until the main thread yields. Uncomment
' the Thread.Sleep that follows t.Start() to see the difference.
t.Start()
'Thread.Sleep(0)
Dim i As Integer
For i = 1 To 4
Console.WriteLine("Main thread: Do some work.")
Thread.Sleep(0)
Next
Console.WriteLine("Main thread: Call Join(), to wait until
ThreadProc ends.")
t.Join()
Console.WriteLine("Main thread: ThreadProc.Join has returned.
Press
Enter to end program.")
Console.ReadLine()
End Sub
End Class
"pascal" <scalefs@hotmail.com> a écrit dans le message de
news:3c244cee.0411090635.2127ae9b@posting.google.com...
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques
secondes a se lancer, pendant se temps je voudrais afficher
un autre formulaire (Form2) pour faire patienter l'utilisateur.
Tout marche bien, sauf que le formulaire (form2) pour patienter
n'affiche pas le contenu que j'ai prévu, mais reste genre
transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement
en attendant le traitement du form1 ?
L'utilisation des threads est élégante, mais tu peux également utiliser plus simplement l'instruction Application.DoEvents Module Module1 Sub Main() Dim f As New Form2 f.Show() Application.DoEvents() Application.Run(New Form1) End Sub End Module
Eric Vernié Microsoft France
"Sébastien" a écrit dans le message de news:
Bonjour,
Tu dois lancer l'execution de ta Form2 dans un thread
voici un exemple de code :
Imports System Imports System.Threading
' Simple threading scenario: Start a Shared method running ' on a second thread. Public Class ThreadExample ' The ThreadProc method is called when the thread starts. ' It loops ten times, writing to the console and yielding ' the rest of its time slice each time, and then ends. Public Shared Sub ThreadProc() Dim i As Integer For i = 0 To 9 Console.WriteLine("ThreadProc: {0}", i) ' Yield the rest of the time slice. Thread.Sleep(0) Next End Sub
Public Shared Sub Main() Console.WriteLine("Main thread: Start a second thread.") ' The constructor for the Thread class requires a ThreadStart ' delegate. The Visual Basic AddressOf operator creates this ' delegate for you. Dim t As New Thread(AddressOf ThreadProc) ' Start ThreadProc. On a uniprocessor, the thread does not get ' any processor time until the main thread yields. Uncomment ' the Thread.Sleep that follows t.Start() to see the difference. t.Start() 'Thread.Sleep(0)
Dim i As Integer For i = 1 To 4 Console.WriteLine("Main thread: Do some work.") Thread.Sleep(0) Next
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.") t.Join() Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.") Console.ReadLine() End Sub End Class
"pascal" a écrit dans le message de news:
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques secondes a se lancer, pendant se temps je voudrais afficher un autre formulaire (Form2) pour faire patienter l'utilisateur. Tout marche bien, sauf que le formulaire (form2) pour patienter n'affiche pas le contenu que j'ai prévu, mais reste genre transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement en attendant le traitement du form1 ?
Merci pour vos réponse
Pascal
Eric Vernié [MS]
Bonjour Sebastien
L'utilisation des threads est élégante, mais tu peux simplement utiliser la méthode Application.DoEvents()
Module Module1 Sub Main() Dim f As New Form2 f.Show() Application.DoEvents() Application.Run(New Form1) End Sub End Module
A+
Eric Vernié Microsoft France
"pascal" a écrit dans le message de news:
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques secondes a se lancer, pendant se temps je voudrais afficher un autre formulaire (Form2) pour faire patienter l'utilisateur. Tout marche bien, sauf que le formulaire (form2) pour patienter n'affiche pas le contenu que j'ai prévu, mais reste genre transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement en attendant le traitement du form1 ?
Merci pour vos réponse
Pascal
Bonjour Sebastien
L'utilisation des threads est élégante, mais tu peux simplement utiliser la
méthode Application.DoEvents()
Module Module1
Sub Main()
Dim f As New Form2
f.Show()
Application.DoEvents()
Application.Run(New Form1)
End Sub
End Module
A+
Eric Vernié
Microsoft France
"pascal" <scalefs@hotmail.com> a écrit dans le message de news:
3c244cee.0411090635.2127ae9b@posting.google.com...
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques
secondes a se lancer, pendant se temps je voudrais afficher
un autre formulaire (Form2) pour faire patienter l'utilisateur.
Tout marche bien, sauf que le formulaire (form2) pour patienter
n'affiche pas le contenu que j'ai prévu, mais reste genre
transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement
en attendant le traitement du form1 ?
L'utilisation des threads est élégante, mais tu peux simplement utiliser la méthode Application.DoEvents()
Module Module1 Sub Main() Dim f As New Form2 f.Show() Application.DoEvents() Application.Run(New Form1) End Sub End Module
A+
Eric Vernié Microsoft France
"pascal" a écrit dans le message de news:
Bonjour à tous,
J'ai un petit soucis, mon formulaire (Form1) de démarrage met qques secondes a se lancer, pendant se temps je voudrais afficher un autre formulaire (Form2) pour faire patienter l'utilisateur. Tout marche bien, sauf que le formulaire (form2) pour patienter n'affiche pas le contenu que j'ai prévu, mais reste genre transparant jusqu'a ce que le form1 a fini son traitement ?
Quelle est la solution pour que mon form2 s'affiche correctement en attendant le traitement du form1 ?