473,837 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

timer ambiguous

I trying to setup a time. The following code is in a function,

Timer stateTimer = new Timer(ab(), null, 1000, 1000);

I have included

using System.Threadin g;

at the begining of my code. When I try to compile I receive the error,

'Timer' is an ambiguous reference

What is the problem?
Nov 16 '05 #1
5 7841
You should put the full namespace path in your constructor.

ex:
System.Threadin g.Timer stateTimer = new System.Threadin g.Timer(ab(),
null, 1000, 1000);

Dave wrote:
I trying to setup a time. The following code is in a function,

Timer stateTimer = new Timer(ab(), null, 1000, 1000);

I have included

using System.Threadin g;

at the begining of my code. When I try to compile I receive the error,

'Timer' is an ambiguous reference

What is the problem?

Nov 16 '05 #2
There are three timers:
System.Timers.T imer
System.Windows. Form.Timer
System.Threadin g.Timer

Decide which one you want to use and write explicit definition, like:
System.Timers.T imer stateTimer = new System.Timers.T imer(ab(), null, 1000,
1000);
"Dave" wrote:
I trying to setup a time. The following code is in a function,

Timer stateTimer = new Timer(ab(), null, 1000, 1000);

I have included

using System.Threadin g;

at the begining of my code. When I try to compile I receive the error,

'Timer' is an ambiguous reference

What is the problem?

Nov 16 '05 #3
That fixed my original problem. I' ve changed the code to;

System.Threadin g.Timer stateTimer = new System.Threadin g.Timer(ab(), null,
1000, 1000);

Now I'm receiving the error, "Argument '1': cannot convert from 'void' to
'System.Threadi ng.TimerCallbac k'

My function is simply as follows, which simply increments a counter;

public void ab()
{
t_count +=1;
}

I don't see that thee is anything to convert. What's causing this error?

"Amiram Korach" wrote:
There are three timers:
System.Timers.T imer
System.Windows. Form.Timer
System.Threadin g.Timer

Decide which one you want to use and write explicit definition, like:
System.Timers.T imer stateTimer = new System.Timers.T imer(ab(), null, 1000,
1000);
"Dave" wrote:
I trying to setup a time. The following code is in a function,

Timer stateTimer = new Timer(ab(), null, 1000, 1000);

I have included

using System.Threadin g;

at the begining of my code. When I try to compile I receive the error,

'Timer' is an ambiguous reference

What is the problem?

Nov 16 '05 #4
Are you sure you need the threading timer? it is more complicated than the
others.
If you still want to use it:

TimerCallback timerDelegate = new TimerCallback(a b);
Timer timer = new Timer(timerDele gate, null, 1000, 1000);

public void ab(object Status)
{
t_count +=1;
}

"Dave" wrote:
That fixed my original problem. I' ve changed the code to;

System.Threadin g.Timer stateTimer = new System.Threadin g.Timer(ab(), null,
1000, 1000);

Now I'm receiving the error, "Argument '1': cannot convert from 'void' to
'System.Threadi ng.TimerCallbac k'

My function is simply as follows, which simply increments a counter;

public void ab()
{
t_count +=1;
}

I don't see that thee is anything to convert. What's causing this error?

"Amiram Korach" wrote:
There are three timers:
System.Timers.T imer
System.Windows. Form.Timer
System.Threadin g.Timer

Decide which one you want to use and write explicit definition, like:
System.Timers.T imer stateTimer = new System.Timers.T imer(ab(), null, 1000,
1000);
"Dave" wrote:
I trying to setup a time. The following code is in a function,

Timer stateTimer = new Timer(ab(), null, 1000, 1000);

I have included

using System.Threadin g;

at the begining of my code. When I try to compile I receive the error,

'Timer' is an ambiguous reference

What is the problem?

Nov 16 '05 #5
It sounds like the stateTimer object is being declared in the scope of
your start button code. You'll need to declare it more global in the
scope of your class so that the stop button code has visibility of
the object.
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Threadin g;

namespace EnvVar
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows. Forms.Form
{
System.Threadin g.Timer oTimer; //visible to entire class code
int iCount;

private System.Windows. Forms.Button StartButton;
private System.Windows. Forms.Button StopButton;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public frmMain()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent
call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.StartButto n = new System.Windows. Forms.Button();
this.StopButton = new System.Windows. Forms.Button();
this.SuspendLay out();
//
// StartButton
//
this.StartButto n.Location = new System.Drawing. Point(208,
192);
this.StartButto n.Name = "StartButto n";
this.StartButto n.TabIndex = 0;
this.StartButto n.Text = "button1";
this.StartButto n.Click += new
System.EventHan dler(this.Start Button_Click);
//
// StopButton
//
this.StopButton .Location = new System.Drawing. Point(192,
232);
this.StopButton .Name = "StopButton ";
this.StopButton .TabIndex = 1;
this.StopButton .Text = "button2";
this.StopButton .Click += new
System.EventHan dler(this.StopB utton_Click);
//
// frmMain
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 273);
this.Controls.A dd(this.StopBut ton);
this.Controls.A dd(this.StartBu tton);
this.Name = "frmMain";
this.Text = "Form1";
this.ResumeLayo ut(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new frmMain());
}

private void StartButton_Cli ck(object sender, System.EventArg s
e)
{
oTimer = new System.Threadin g.Timer( new
TimerCallback(a b), null, 1000, 1000 );
}
private void StopButton_Clic k(object sender, System.EventArg s
e)
{
oTimer.Dispose( );
}

public void ab( Object state )
{
iCount++;
}
}
}

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #6

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

Similar topics

10
6831
by: Bill | last post by:
I have an asp page that will be updating the data from one database into my sql server database every 3 hours. I'd like to write code that will tell the page to automatically run every three hours. How do I do this? Thanks, Bill
9
3980
by: xuatla | last post by:
compile error: test1.cpp:21: error: ISO C++ says that `T mtd::CDiffOperator::getdp(const mtd::mVector&, long int, mtd::mBCTYPE) const' and `void mtd::CDiffOperator::getdp(mtd::mVector&, const mtd::mVector&, mtd::mBCTYPE) const' are ambiguous even though the worst conversion for the former is better than the worst conversion for the latter
1
10018
by: Alex Zhitlenok | last post by:
Hi, My question is how to resolve in C# ambiguous overloaded operators? Let say, I have two unrelated classes A and B, each one implements overloaded operator + with the first parameter of type A, and the second one of type B. Let say, these are not my classes and I know nothing about the implementation. As system doesn't know what code must be used for resolving the language construction a+b (where A a; and B b;), it returns "The call...
5
4558
by: Brett | last post by:
If I use the following code, the declaration is fine. //no namespace private System.Timers.Timer Clock; This gives the error, "'Timer' is an ambiguous reference". using System.Timers; //namespace doesn't make a difference .... private Timer Clock; What am I doing wrong?
17
2126
by: Gaijinco | last post by:
How can I write a program to be executed for a given ammount of time. I mean I want to write a program that once started it doesn't do anything for like 2 minutes and then exits. It is possible?
9
13284
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include <hash_map>//from Standard template library //and some other headers
3
1879
by: Arpan | last post by:
The following code exists in a class file named "Users.vb": Namespace Users Public Class UserDetails Public FirstName As String Public LastName As String Public UserName As String Public Password As String Public UserID As String End Class
1
1528
by: rn5a | last post by:
Consider the following code in a VB class file: Namespace LoginUserFetchDB Public Class ZForZebra : Inherits SoapHeader Public UserName As String Public Password As String End Class Public Class GetDBRecords : Inherits WebService Private sqlCmd As SqlCommand
12
2050
by: Nathan Sokalski | last post by:
I have several CustomControls that I have written for my project. However, when I try to compile I recieve the following warning & errors: Warning 32 Could not resolve this reference. Could not locate the assembly "nathansokalski_com_test, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors....
0
10577
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
10630
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
10275
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
9407
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
7811
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
5670
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5851
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4476
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4045
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.