thorpedosg

9YCzJ1Mv

Aug 6th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. Populating+a+listview+from+another+thread%0Aclass+CheckBlankPages%0A%7B%0A%0A++++public+String%5B%5D+pdfFiles%0A++++%7B+get%3B+set%3B+%7D%0A%0A++++ListView+_ListVireRef%3B%0A++++public+int+NrCRT+%3D+1%3B%0A%0A%0A++++public+CheckBlankPages%28String%5B%5D+pdfFiles+%3D+null%2C+ListView+listView+%3D+null%29%0A++++%7B%0A++++++++this.pdfFiles+%3D+pdfFiles%3B%0A++++++++_ListVireRef+%3D+listView%3B%0A%0A++++%7D%0A++++public+void+StartCheckingPDF%28%29%0A++++%7B%0A++++++++foreach+%28string+pdf+in+pdfFiles%29%0A++++++++%7B%0A++++++++++++String%5B%5D+itm+%3D+%7B+%28NrCRT%2B%2B%29.ToString%28%29%2C+pdf+%7D%3B%0A++++++++++++ListViewItem+item+%3D+new+ListViewItem%28itm%29%3B%0A++++++++++++_ListVireRef.Items.Add%28item%29%3B%0A++++++++%7D%0A++++%7D%0A%7D%0A%09%0ADialogResult+rezultat+%3D+openFileDialog1.ShowDialog%28%29%3B%0A++++++++if+%28rezultat+%3D%3D+DialogResult.OK%29%0A++++++++%7B%0A%0A++++++++++++CheckBlankPages+ck+%3D+new+CheckBlankPages%28openFileDialog1.FileNames%2C+listView1%29%3B%0A++++++++++++Thread+CheckPDFs+%3D+new+Thread%28new+ThreadStart%28ck.StartCheckingPDF%29%29%3B%0A++++++++++++CheckPDFs.Start%28%29%3B%0A++++++++%7D%0A%09%0Ausing+System%3B%0Ausing+System.Windows.Forms%3B%0A%0Anamespace+TestWinFormsThreding%0A%7B%0A++++class+TestFormCotrolHelper%0A++++%7B%0A++++++++delegate+void+UniversalVoidDelegate%28%29%3B%0A%0A++++++++%2F%2F%2F+%0A++++++++%2F%2F%2F+Call+form+controll+action+from+different+thread%0A++++++++%2F%2F%2F+%0A++++++++public+static+void+ControlInvike%28Control+control%2C+Action+function%29%0A++++++++%7B%0A++++++++++++if+%28control.IsDisposed+%7C%7C+control.Disposing%29%0A++++++++++++++++return%3B%0A%0A++++++++++++if+%28control.InvokeRequired%29%0A++++++++++++%7B%0A++++++++++++++++control.Invoke%28new+UniversalVoidDelegate%28%28%29+%3D%3E+ControlInvike%28control%2C+function%29%29%29%3B%0A++++++++++++++++return%3B%0A++++++++++++%7D%0A++++++++++++function%28%29%3B%0A++++++++%7D%0A++++%7D%0A%0A++++public+partial+class+TestMainForm+%3A+Form%0A++++%7B%0A++++%2F%2F+...%0A++++%2F%2F+This+will+be+called+from+thread+not+the+same+as+MainForm+thread%0A++++private+void+TestFunction%28%29%0A++++%7B%0A++++++++TestFormCotrolHelper.ControlInvike%28listView1%2C+%28%29+%3D%3E+listView1.Items.Add%28%22Test%22%29%29%3B%0A++++%7D+++%0A++++%2F%2F...%0A++++%7D%0A%7D%0A%09%0Aprivate+delegate+void+MyDelegate%28string+s%29%3B%0A%0Apublic+void+UpdateControl%28Control+targetControl%2C+string+text%29%0A%7B%0A++++if+%28targetControl.InvokeRequired%29%0A++++%7B%0A++++++++%2F%2F+THIS+IS+STILL+THE+IN+THE+CONTEXT+OF+THE+THREAD%0A++++++++MyDelegate+call+%3D+new+MyDelegate%28UpdateControl%29%3B%0A++++++++targetControl.Invoke%28call%2C+new+object%5B%5D+%7B+text+%7D%29%3B%0A++++%7D%0A++++else%0A++++%7B%0A++++++++%2F%2F+do+control+stuff%0A++++++++%2F%2F+THIS+IS+IN+THE+CONTEXT+OF+THE+UI+THREAD%0A++++%7D%0A%7D%0A%09%0AAction+action+%3D+new+Action%28%28%29+%3D%3E%0A++++%7B+%0A++++++++%2F%2F+Add+item+to+list+view+here++%0A++++%7D%29%3B%0A++++if+%28_ListVireRef.InvokeRequired%29%0A++++%7B%0A++++++++_ListVireRef.BeginInvoke%28action%29%3B+%2F%2F+or+Invoke+if+wanting+to+call+synchronously.%0A++++%7D%0A++++else%0A++++%7B%0A++++++++action%28%29%3B%0A++++%7D
Add Comment
Please, Sign In to add comment