473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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.Threading;

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 7765
You should put the full namespace path in your constructor.

ex:
System.Threading.Timer stateTimer = new System.Threading.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.Threading;

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.Timer
System.Windows.Form.Timer
System.Threading.Timer

Decide which one you want to use and write explicit definition, like:
System.Timers.Timer stateTimer = new System.Timers.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.Threading;

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.Threading.Timer stateTimer = new System.Threading.Timer(ab(), null,
1000, 1000);

Now I'm receiving the error, "Argument '1': cannot convert from 'void' to
'System.Threading.TimerCallback'

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.Timer
System.Windows.Form.Timer
System.Threading.Timer

Decide which one you want to use and write explicit definition, like:
System.Timers.Timer stateTimer = new System.Timers.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.Threading;

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(ab);
Timer timer = new Timer(timerDelegate, 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.Threading.Timer stateTimer = new System.Threading.Timer(ab(), null,
1000, 1000);

Now I'm receiving the error, "Argument '1': cannot convert from 'void' to
'System.Threading.TimerCallback'

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.Timer
System.Windows.Form.Timer
System.Threading.Timer

Decide which one you want to use and write explicit definition, like:
System.Timers.Timer stateTimer = new System.Timers.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.Threading;

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.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace EnvVar
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
System.Threading.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.ComponentModel.Container components = null;

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

//
// TODO: Add any constructor code after InitializeComponent
call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.StartButton = new System.Windows.Forms.Button();
this.StopButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// StartButton
//
this.StartButton.Location = new System.Drawing.Point(208,
192);
this.StartButton.Name = "StartButton";
this.StartButton.TabIndex = 0;
this.StartButton.Text = "button1";
this.StartButton.Click += new
System.EventHandler(this.StartButton_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.EventHandler(this.StopButton_Click);
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.StopButton);
this.Controls.Add(this.StartButton);
this.Name = "frmMain";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

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

private void StartButton_Click(object sender, System.EventArgs
e)
{
oTimer = new System.Threading.Timer( new
TimerCallback(ab), null, 1000, 1000 );
}
private void StopButton_Click(object sender, System.EventArgs
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
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....
9
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...
1
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...
5
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; ...
17
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...
9
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...
3
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...
1
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...
12
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.