Click here to Skip to main content
15,896,348 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Could not load file or assembly or one of its dependencies. Pin
fjdiewornncalwe21-Aug-12 6:25
professionalfjdiewornncalwe21-Aug-12 6:25 
GeneralRe: Could not load file or assembly or one of its dependencies. Pin
Eddy Vluggen21-Aug-12 3:23
professionalEddy Vluggen21-Aug-12 3:23 
GeneralRe: Could not load file or assembly or one of its dependencies. Pin
Karthik Chintala21-Aug-12 3:32
Karthik Chintala21-Aug-12 3:32 
GeneralRe: Could not load file or assembly or one of its dependencies. Pin
Dave Kreskowiak21-Aug-12 3:39
mveDave Kreskowiak21-Aug-12 3:39 
AnswerRe: Could not load file or assembly or one of its dependencies. Pin
Bernhard Hiller21-Aug-12 21:07
Bernhard Hiller21-Aug-12 21:07 
QuestionMessage Removed Pin
20-Aug-12 7:49
professionaljkirkerx20-Aug-12 7:49 
QuestionNot Understanding Delegates (User Error) Pin
Clark Kent12320-Aug-12 4:23
professionalClark Kent12320-Aug-12 4:23 
AnswerRe: Not Understanding Delegates (User Error) Pin
Eddy Vluggen20-Aug-12 13:00
professionalEddy Vluggen20-Aug-12 13:00 
A Delegate is a method-pointer, you could look at it as an interface on a method-only-level. That means that it defines a Type, like an Integer, but not for data, but for methods. That means you can store a reference to a method.

When a single-threaded application is executed, it's the UI-thread or the main-thread that builds the controls. A thread executes the instructions in the code one after another. That's why you sometimes see a form go completely white when it is doing a lot of processing; the UI thread is too busy to do the drawing. To prevent that from happening, and have a responsive UI, we do the heavy work on a separate thread.

Clark Kent123 wrote:
-Where should the delegate be created within my program? Form1? Form2?

On the place where you intend to call it, you'll need an instance. That instance could be passed using a parameter, as a Delegate is a Type that "acts" as a variable.

Clark Kent123 wrote:
-Should the Delegates be created on both forms?

No, but the delegate is often public, so that it's Type can be used in other forms (from where it's called, for instance)

Clark Kent123 wrote:
-Should I use BeginInvoke instead of Invoke?

Invoke should execute it on the same thread; that Exception you mention should only occur when you use BeginInvoke, as that creates a new thread. In that case you'll also need the Invoke-pattern[^].

Clark Kent123 wrote:
-Is Delegates indeed the correct route to go? Should I use Threading?

You should be able to answer that by yourself now; threading is for heavy tasks, delegates are method-variables. Here's an example that uses both;
VB
Imports System.Windows.Forms
Imports System.Threading

Public Delegate Sub MyCallbackProto(Count As Integer)

Public Class TheThreadClass: Inherits Object 
	Private mySomeCallbackRoutine As MyCallbackProto
	Private myThread As Thread

	Public Sub New(aSomeCallback As MyCallbackProto)
		mySomeCallbackRoutine = aSomeCallback
		myThread = New Thread(AddressOf Work)
		myThread.Start
	End Sub
	
	Public Sub Work()
		For i As Integer = 0 To 100
			Thread.Sleep(50)
			'here we call the method, executes in the
			'form class below
			mySomeCallbackRoutine(i)
		Next		
		Application.Exit ' when the work is done, exit
	End Sub	
End Class

Public Class Form1: Inherits Form
	Private myProgressBar As New ProgressBar
	Private myThread As TheThreadClass

	Public Sub New()
		Controls.Add(myProgressBar)
		'and here we put the method OnUpdate in the parameter;
		myThread = new TheThreadClass(AddressOf OnUpdate)
	End Sub
	
	Sub OnUpdate(Count As Integer)
		myProgressBar.Value = Count
	End Sub
End Class

Public Class MyApp
	Public Shared Sub Main()
		Application.Run(New Form1())
	End Sub	
End Class

Another cool intro to delegates is the A Beginner's Guide to Delegates[^] article. There is a series (5 articles I believe) on threads called Beginners Guide to Threading in .NET: Part 1 of n[^].

Enjoy Smile | :)
Bastard Programmer from Hell Suspicious | :suss:
if you can't read my code, try converting it here[^]

GeneralRe: Not Understanding Delegates (User Error) Pin
Clark Kent12321-Aug-12 2:29
professionalClark Kent12321-Aug-12 2:29 
GeneralRe: Not Understanding Delegates (User Error) Pin
Eddy Vluggen21-Aug-12 2:56
professionalEddy Vluggen21-Aug-12 2:56 
GeneralRe: Not Understanding Delegates (User Error) Pin
Clark Kent12321-Aug-12 4:28
professionalClark Kent12321-Aug-12 4:28 
GeneralRe: Not Understanding Delegates (User Error) Pin
Eddy Vluggen21-Aug-12 4:50
professionalEddy Vluggen21-Aug-12 4:50 
QuestionMultiple checkbox in Excel file Pin
oanaa1119-Aug-12 21:20
oanaa1119-Aug-12 21:20 
AnswerRe: Multiple checkbox in Excel file Pin
Sonhospa19-Aug-12 23:37
Sonhospa19-Aug-12 23:37 
AnswerRe: Multiple checkbox in Excel file Pin
Clark Kent12320-Aug-12 3:26
professionalClark Kent12320-Aug-12 3:26 
AnswerStore Keywords in Excel doc Pin
David Mujica20-Aug-12 4:02
David Mujica20-Aug-12 4:02 
AnswerCode snipet Pin
David Mujica20-Aug-12 4:30
David Mujica20-Aug-12 4:30 
GeneralRe: Code snipet Pin
oanaa1120-Aug-12 20:10
oanaa1120-Aug-12 20:10 
QuestionHow to code the next button Pin
garyu8717-Aug-12 22:09
garyu8717-Aug-12 22:09 
AnswerRe: How to code the next button Pin
Eddy Vluggen18-Aug-12 2:05
professionalEddy Vluggen18-Aug-12 2:05 
GeneralRe: How to code the next button Pin
garyu8718-Aug-12 2:38
garyu8718-Aug-12 2:38 
GeneralRe: How to code the next button Pin
Eddy Vluggen18-Aug-12 5:49
professionalEddy Vluggen18-Aug-12 5:49 
GeneralRe: How to code the next button Pin
garyu8718-Aug-12 20:01
garyu8718-Aug-12 20:01 
GeneralRe: How to code the next button Pin
Eddy Vluggen18-Aug-12 23:21
professionalEddy Vluggen18-Aug-12 23:21 
Questionvb interface wih HP impedance tester Pin
seow22716-Aug-12 21:55
seow22716-Aug-12 21:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.