2 Replies - 518 Views - Last Post: 12 May 2009 - 07:58 PM Rate Topic: -----

#1 voodookittyrob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-May 09

Constantly returning a value from a funtion

Post icon  Posted 12 May 2009 - 06:00 PM

How would one receive a value from a function while it is running?
Is This A Good Question/Topic? 0
  • +

Replies To: Constantly returning a value from a funtion

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4313
  • View blog
  • Posts: 12,090
  • Joined: 18-April 07

Re: Constantly returning a value from a funtion

Posted 12 May 2009 - 06:49 PM

Well the idea is that once you return you leave the function. That is the thought behind what a function is, takes some input, does some calculations and returns the result. It would be like asking how do you return PI while you are executing a function to calculate the area of a circle. Doesn't make a whole lot of sense.

Now if you are looking to do something over and over again on a timed basis, then you could simply use a timer control to call a function (or return a variable value). For that look into the timer_tick event of the timer control. This event is fired every so many X milliseconds based on the interval you give the timer.

But as far as returning a value from a function as it is doing something else is not the way things work.

Perhaps you can show us what you are looking to do. :)
Was This Post Helpful? 0
  • +
  • -

#3 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Constantly returning a value from a funtion

Posted 12 May 2009 - 07:58 PM

Is this a kinda what your trying to do?

Imports System.Threading

Module Program
	Private int_PassOut As Integer 
	private obj_Lock as New Object
	Sub Main()
		ThreadPool.QueueUserWorkItem(new WaitCallback(addressof work),nothing)
		While True
			SyncLock(obj_lock)
				Console.WriteLine(Int_passOut)
			End SyncLock
			Thread.Sleep(300)
		End While
	End Sub
	Private Sub Work()
		While True
			SyncLock(obj_Lock)
			int_passOut+= 1
			End SyncLock
			Thread.Sleep(150)
		End While
	End Sub
End Module

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1