471,336 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

Anonymous Method syntax issue

Folks,

Sorry to take up bandwidth, but for the life of me I cannot see the syntax
error in this code:

Timer myTimer = new Timer();
myTimer.Tick += delegate {
stopWaiting = true;
};

The compiler error indicates that the parser is exepcting a "}" at the "."
in the second line. This is the first error in the source file.

By the way, the same error is thrown if I use either of these two variations:

myTimer.Tick += delegate() {
stopWaiting = true;
};

myTimer.Tick += delegate(object sender, EventArgs e) {
stopWaiting = true;
};

Thanks in advance for your assistance.

/Joel Finkel
fi****@sd-il.com
Jan 26 '06 #1
3 1158
Joel Finkel <Jo********@discussions.microsoft.com> wrote:
Sorry to take up bandwidth, but for the life of me I cannot see the syntax
error in this code:

Timer myTimer = new Timer();
myTimer.Tick += delegate {
stopWaiting = true;
};

The compiler error indicates that the parser is exepcting a "}" at the "."
in the second line. This is the first error in the source file.


Are you absolutely sure you're using the C# 2.0 compiler? This code
compiles fine on my box with 2.0, but gives the same kind of error
you're talking about if I try to compile it with 1.1...

using System;
using System.Windows.Forms;

public class Test
{
static Timer myTimer;

static bool stopWaiting;

static void Main()
{
myTimer = new Timer();

myTimer.Tick += delegate(object sender, EventArgs e)
{
stopWaiting = true;
};

myTimer.Tick += delegate { stopWaiting = true; };
}

}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 26 '06 #2
> Folks,

Sorry to take up bandwidth, but for the life of me I cannot see the
syntax error in this code:

Timer myTimer = new Timer();
myTimer.Tick += delegate {
stopWaiting = true;
};
Compiles over here.
The compiler error indicates that the parser is exepcting a "}" at the
"." in the second line. This is the first error in the source file.

By the way, the same error is thrown if I use either of these two
variations:

myTimer.Tick += delegate() {
stopWaiting = true;
};
Won't compile.
myTimer.Tick += delegate(object sender, EventArgs e) {
stopWaiting = true;
};
Thanks in advance for your assistance.

Compiles fine.
/Joel Finkel
fi****@sd-il.com


I can't get the event to fire though.
Jan 26 '06 #3
I have not a clue what the problem is. I brought the code into an existing
project and it compiles fine. Somehow, there must have been some crud in the
editor.

Hmmm...I guess that means I DO have a clue what the problem is; but I'm not
going to pursue it further.

Thanks.

"chris martin" wrote:
Folks,

Sorry to take up bandwidth, but for the life of me I cannot see the
syntax error in this code:

Timer myTimer = new Timer();
myTimer.Tick += delegate {
stopWaiting = true;
};


Compiles over here.
The compiler error indicates that the parser is exepcting a "}" at the
"." in the second line. This is the first error in the source file.

By the way, the same error is thrown if I use either of these two
variations:

myTimer.Tick += delegate() {
stopWaiting = true;
};


Won't compile.
myTimer.Tick += delegate(object sender, EventArgs e) {
stopWaiting = true;
};
Thanks in advance for your assistance.


Compiles fine.
/Joel Finkel
fi****@sd-il.com


I can't get the event to fire though.

Jan 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Doug Holton | last post: by
reply views Thread by Carlos Ribeiro | last post: by
31 posts views Thread by Chris S. | last post: by
76 posts views Thread by Nick Coghlan | last post: by
reply views Thread by Cordell Lawrence | last post: by
2 posts views Thread by Marcos Stefanakopolus | last post: by
3 posts views Thread by anonymous | last post: by
7 posts views Thread by moondaddy | last post: by
4 posts views Thread by Frankie | last post: by
reply views Thread by Peter Duniho | last post: by
reply views Thread by rosydwin | last post: by

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.