Calling a method asynchronously: “Expression does not produce a value.”
Posted on 2006-10-24
I’m experimenting with Threading and asynchronous calls. I had these calls working great in VS2003, but now things have changed in VS2005 and I'm having problems. I have a test that I’m performing but ran into a snag. You can see the line with the Messagebox.Show that is giving the error “Expression does not produce a value”. I’ve stared at this for the longest time and it looks right to me. Can you spot where I’m going wrong? My first section of code is from the Windows Form and the 2nd section is another Class that has a very simple subroutine to similate a long call to a database or network slowness.
Or maybe you think I'm going about this the hard way and that there's a better way to put Subs and Functions into another Thread. Thank you for looking at this.
I’m using Visual Studio 2005 with .NET 2.0, with VB.NET.
Public Class frmLogger
Private Delegate Sub DoTest()
Private myDoTest As DoTest = New DoTest(AddressOf Logger.readTHIS)
Public Sub myTestCallBack(ByVal myAr As IAsyncResult)
MessageBox.Show(myDoTest.EndInvoke(myAr)) 'This line shows error on compiling:“Expression does not produce a value.”
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Dim myCallBack As AsyncCallback = New AsyncCallback(AddressOf Me.myTestCallBack)
Dim myAr As IAsyncResult = myDoTest.BeginInvoke(myCallBack, Nothing)
Public Class Logger
Public Shared Sub readTHIS()
frmLogger.Label1.Text = "We are starting"
frmLogger.Label1.Text = "After 3 second sleep"
frmLogger.Label1.Text = "After 5 second sleep"