473,661 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with async callback

I wrote a test program to help understand asynchronous calls in c#. I
have a working VB.NET app that uses a similar technique but I cannot
get it to work in c#. The errors I get and the code below. I
understand the need for threading when updating UI and the general
concept of what is going on but do not understand the two errors.:

Error 1 'testwinform.Fo rm1.WorkDoneDel egate()' must declare a body
because it is not marked abstract or extern C:\Development\ testwinform
\testwinform\Fo rm1.cs 20 26 testwinform
Error 2 'testwinform.Wo rker.AsyncMetho dCaller()' must declare a body
because it is not marked abstract or extern C:\Development\ testwinform
\testwinform\Wo rker.cs 21 26 testwinform

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Threadin g;

namespace testwinform
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();

}

public Delegate WorkDoneDelegat e();

private void btnStart_Click( object sender, EventArgs e)
{
Worker ad = new Worker();
AsyncMethodCall er caller = new
AsyncMethodCall er(ad.WorkerThr ead);
IAsyncResult result = caller.BeginInv oke(CallBackMet hod);

}

private void CallBackMethod( IAsyncResult result)
{
AsyncMethodCall er caller =
AsyncMethodCall er(result.Async State);
string returnvalue = caller.EndInvok e(result);
if (this.lblMessag e.InvokeRequire d)
{
WorkDoneDelegat e wd = new
WorkDoneDelegat e(CallBackMetho d);
this.Invoke(wd, new object()(return value));
}
else
lblMessage.Text = "Done";
}
}
}

//here is the class with the worker thread
using System;
using System.Collecti ons.Generic;
using System.Text;

namespace testwinform
{
class Worker
{
public Worker()
{
}

public string WorkerThread()
{
Thread.Sleep(10 );
return ("Done");
}
//delegate used in asynchronous callback
public Delegate AsyncMethodCall er();

}
}

Nov 2 '07 #1
2 2065
On 2007-11-01 16:56:46 -0700, bi*********@yah oo.com said:
I wrote a test program to help understand asynchronous calls in c#. I
have a working VB.NET app that uses a similar technique but I cannot
get it to work in c#. The errors I get and the code below. I
understand the need for threading when updating UI and the general
concept of what is going on but do not understand the two errors.:

Error 1 'testwinform.Fo rm1.WorkDoneDel egate()' must declare a body
because it is not marked abstract or extern C:\Development\ testwinform
\testwinform\Fo rm1.cs 20 26 testwinform
Error 2 'testwinform.Wo rker.AsyncMetho dCaller()' must declare a body
because it is not marked abstract or extern C:\Development\ testwinform
\testwinform\Wo rker.cs 21 26 testwinform
The error gives you a very strong hint as to what the problem is. The
compiler is interpreting your attempts to define a delegate as though
they are method declarations. So, you should look at the declarations
with that in mind. Why would the compiler think they are method
declarations? Because they are more like a method declaration than a
delegate declaration.

Two problems:

1) There is no return type specified in your declaration for the delegate
2) You are using "Delegate" instead of "delegate" to declare the delegate

All delegate declarations must include a complete method signature, and
no method signature is complete without a return type.

"Delegate" is a type. "delegate" is a C# keyword used to declare a
type that inherits "Delegate".

Because of these issues, the compiler looks at the declaration and
sees: "return type, method name, empty parameter list" and says "ah, a
method declaration...b ut, there's no body!" Thus the error.

Hope that helps.

Pete

Nov 2 '07 #2
Thanks, Pete. I have everything working now.

On Nov 1, 6:26 pm, Peter Duniho <NpOeStPe...@Nn OwSlPiAnMk.comw rote:
Because of these issues, the compiler looks at the declaration and
sees: "return type, method name, empty parameter list" and says "ah, a
method declaration...b ut, there's no body!" Thus the error.

Hope that helps.

Pete

Nov 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7133
by: scott ocamb | last post by:
hello I have implemented a solution using async methods. There is one async method that can be invoked multiple times, ie there are multiple async "threads" running at a time. When these threads are complete, the call the Callback method. Each "thread" calls the same callback method. What thread does this callback method exist on? My testing indicates the
1
6573
by: Mark Smith | last post by:
Hi , Is it possible in .Net to define a async timer callback. What I am wanting to do is declare a time-out condition that gets executed should the something timeout. The reason I want to do this is to handle host being down that I am trying to connect to using TCPIP. Then after a timeout automatically try another host and just continue trying hosts until someone accepts a connection, varying my timeout as I loop.
4
2956
by: Brett Robichaud | last post by:
I'm using an async delegate to spawn a thread and run some code. I also specify an AsyncCallback to get notified when the thread completes. The problem is that my callback is being called twice and I can't figure out why. Here is a snippet of my code, the LoadImageThreadComplete() method is being called twice even though LoadImage() is only ever called once. Any ideas why? delegate void LoadImageDelegate(string file); private void...
6
1818
by: TS | last post by:
Im in a web page and call an asynchronous method in business class. the call back method is in the web page. When page processes, it runs thru code begins invoking the method then the page unloads. When the callback method is raised, only the method in the web page is run and the page never refreshes, it seems it all happens on the server side. I am trying to refresh the constrols on the page inside the callback method, but when id...
11
1758
by: Glen Wolinsky | last post by:
This is my first attempt as asynchronous processing. I have created a small test app as proof of concept, but I am having one proglem. In the example (code listed below), my callback routine has two problems: 1. It runs TWICE; and 2. While it seems to update the web page controls, the results never show up on the page. I am using delegates per a couple of examples I found on MSDN and elsewhere.
2
1248
by: ITALstudio s.r.l. | last post by:
Hy, I make an async call, using delegate and BeginInvoke. When the async call is completed, the callback procedure is executed two times. I debugged the code and I'm sure: I make one async call, but the callback procedure is executed two times. I use the Framework 1.1 SP1.
2
3405
by: Anand | last post by:
Hi Season Greetings, I'm trying to implement client call backs in my page. i'm using user controls (composite controls) and these are placed in my master page. I'm implementing ICallbackEventHandler and ICallbackContainer interfaces in my user control class to generate the callback, and i palced the respective javascript function in master page to receive results, and populated to a asp list box (typically i've to populate a list box...
0
2082
by: whizpop | last post by:
Hi, First of all, thanks for a great starter kit, now If I could just get it to work (fully). I am trying to compile and run the solution/services all on a local dev box. I am able to successfully run most of the SampleApp features (Register,Feedback,Error report, version check) The only method I can not execute is the BuyNow example. I have tried leveraging the Sharewarestarterkit.com web service to rule out locality, to no avail.
1
4438
by: Demi | last post by:
I'm trying to use an Async="true" page to do an async HttpWebRequest. My code is based on the MSDN example: http://msdn2.microsoft.com/en-us/library/21k58ta7.aspx The problem I'm having is that I'm not sure how to wait until my response has finished arriving. It's jumping to EndGetAsyncData when I first get the response instead of when I finish reading it. Looking at the code I can see why it's doing this, but I'm not sure how I can...
8
8924
by: Chizl | last post by:
I'm building a web server and having some issues with the TCPListener.Start(BackLog). It doesn't seem to do as expected. I'm using MS Web Stress Tool to test against my web server and when I see 200 connections at once to it, and I'm seeing 2/3 of the sockets as socket errors.. They never get into my code, so it has to be failing on the connection side.. Backlog is the only thing I can think could be the problem. ...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8758
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.