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
App. WinForms / WPF .NET
Includere un swf in una winform
lunedì 04 settembre 2006 - 12.06
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
andreapavia
Profilo
| Senior Member
203
messaggi | Data Invio:
lun 4 set 2006 - 12:06
ciao a tutti... ho sviluppato una progressbar fittizia nella mia winform... e funziona...
ma durante lo scambio di dati col database la prgressbar si blocca perche le risorse della wf credo siano tutte x il trasferimento del dataset...
posso ovviare questo problema inserendo una progressbar fittizia fatta in flash???
Giamp72
Profilo
| Junior Member
115
messaggi | Data Invio:
lun 4 set 2006 - 12:37
..e perchè invece non usi un timer per l'aggiornamento della barra??
utilizzando opportunamente i thread o il doevents potresti risolvere senza complicarti troppo la vita...
Giamp72
andreapavia
Profilo
| Senior Member
203
messaggi | Data Invio:
mer 6 set 2006 - 11:07
scusami... mi potresti farmi un esmpio...
Private Sub ButtonLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLogin.Click
myprogressbar.run()
doTheSelectAndBindDG()
myprogressbar.stopAndClose()
end sun
come faccio a settare i mieie oggetti in modo che siano indipendenti tramite thread in modo che la progress non smetta di fare avanti-indietro durante la sub (doTheSelectAndBindDG) perche' tutte le risorse passano alla select, poi alla costruzione del dataset e al binding del datagrid????
grazie 1000
Giamp72
Profilo
| Junior Member
115
messaggi | Data Invio:
mer 6 set 2006 - 11:37
Ecco un modo per risolvere la cosa:
Private thr As New Threading.Thread(AddressOf myprogressbarRun )
Private Sub ButtonLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLogin.Click
thr.IsBackground = True
thr.Start()
doTheSelectAndBindDG()
myprogressbar.stopAndClose()
end sub
in pratica dichiari un thread legato alla subroutine di aggiornamento, e poi impostando IsBackground lo fai lanciare in maniera asincrona...
L'altra soluzione (forse + immediata) è quella di mettere
Application.DoEvents()
all'interno del tuo ciclo di query (credo nella funzione doTheSelectAndBindDG) ad ogni doevents il sistema cerca di rispondere ai vari messaggi che ha in coda.. come ad esempio l'aggiornamento della tua progress per ritornare poi al processo doTheSelectAndBindDG... Okkio perchè se usi questa strada anche i vari click sulla form vengono intercettati come eventi cui il sistema cerca di rispondere...
fammi sapere..
Giamp72
andreapavia
Profilo
| Senior Member
203
messaggi | Data Invio:
mer 6 set 2006 - 14:17
Intanto grazie 1000
Private Sub ButtonLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLogin.Click
Dim MyThread As New Thread(AddressOf startProgressbar)
MyThread.IsBackground = True
MyThread.Start()
subDiSelectCostrizioneBindingCheFatutto()
stopProgressbar()
MyThread.Suspend()
End Sub
Private Sub startProgressbar()
Mkc_BouncingProgress1.Bounce = Not Mkc_BouncingProgress1.Bounce
End Sub
Private Sub stopProgressbar()
Mkc_BouncingProgress1.Bounce = Not Mkc_BouncingProgress1.Bounce
End Sub
Private Sub StatusBar1_DrawItem(ByVal sender As Object, ByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) Handles StatusBar1.DrawItem
' use the drawing rect to set bounds
If sbdevent.Panel Is StatusBarPanel2 Then
Dim Rect As New Rectangle(sbdevent.Bounds.X + 1, sbdevent.Bounds.Y + 1, sbdevent.Bounds.Width - 2, sbdevent.Bounds.Height - 2)
Mkc_BouncingProgress1.Bounds = Rect
End If
End Sub
E' la prima volta che uso un thread... questo è il codice riguardante la progresssbar...
Ora la progress non parte neanche e catturo questa eccezione: "il thread non puo essere sospeso perche' non è in esecuzione"...
Giamp72
Profilo
| Junior Member
115
messaggi | Data Invio:
mer 6 set 2006 - 14:36
'il dim va fatto qui...
Dim MyThread As New Thread(AddressOf startProgressbar)
Private Sub ButtonLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLogin.Click
MyThread.IsBackground = True
MyThread.Start()
subDiSelectCostrizioneBindingCheFatutto()
stopProgressbar()
MyThread.Suspend()
End Sub
Private Sub startProgressbar()
Mkc_BouncingProgress1.Bounce = Not Mkc_BouncingProgress1.Bounce
End Sub
Private Sub stopProgressbar()
Mkc_BouncingProgress1.Bounce = Not Mkc_BouncingProgress1.Bounce
End Sub
Private Sub StatusBar1_DrawItem(ByVal sender As Object, ByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) Handles StatusBar1.DrawItem
' use the drawing rect to set bounds
If sbdevent.Panel Is StatusBarPanel2 Then
Dim Rect As New Rectangle(sbdevent.Bounds.X + 1, sbdevent.Bounds.Y + 1, sbdevent.Bounds.Width - 2, sbdevent.Bounds.Height - 2)
Mkc_BouncingProgress1.Bounds = Rect
End If
End Sub
Prova così.. non ho testato il sorgente.. però credo il problema fosse la dichiarazione del thread...
ciao
Giamp72
andreapavia
Profilo
| Senior Member
203
messaggi | Data Invio:
mer 6 set 2006 - 14:45
ho fatto esattamente come mi hai detto ora...
ma non è cambiato nulla....
non ho la piu' pallida idea di come funzioni....
Giamp72
Profilo
| Junior Member
115
messaggi | Data Invio:
mer 6 set 2006 - 15:38
crea un form con un bottone e 2 text box, poi prova questo codice..
Imports System.Threading
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Codice generato da Progettazione Windows Form "
Public Sub New()
MyBase.New()
'Chiamata richiesta da Progettazione Windows Form.
InitializeComponent()
'Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent()
End Sub
'Form esegue l'override del metodo Dispose per pulire l'elenco dei componenti.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Richiesto da Progettazione Windows Form
Private components As System.ComponentModel.IContainer
'NOTA: la procedura che segue è richiesta da Progettazione Windows Form.
'Può essere modificata in Progettazione Windows Form.
'Non modificarla nell'editor del codice.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(112, 64)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(88, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 136)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(144, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(88, 184)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(120, 20)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Dim MyThread As New Thread(AddressOf test1)
Dim MyThread2 As New Thread(AddressOf test)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MyThread.IsBackground = True
MyThread.Priority = ThreadPriority.BelowNormal
MyThread.Start()
MyThread2.IsBackground = True
MyThread2.Priority = ThreadPriority.Normal
MyThread2.Start()
End Sub
Sub test()
Dim k As Long
Do
k = k + 1
If k > 10000 Then k = 0
' Application.DoEvents()
textbox2.text = k
Loop
End Sub
Sub test1()
Dim k As Long
Do
k = k + 1
If k > 10000 Then k = 0
' Application.DoEvents()
TextBox1.Text = k
Loop
End Sub
End Class
come vedrai le due funzioni test e test 1 girano in maniera asincrona.. in questo modo puoi dare anche una priorità al processo che ti interessa di più...
Giamp72
Giamp72
Profilo
| Junior Member
115
messaggi | Data Invio:
gio 7 set 2006 - 08:38
..e quindi? sei riuscito?? funziona??
Giamp72
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 !