473,657 Members | 2,419 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 7811
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
6814
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
3964
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
9998
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
4550
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
2110
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
13265
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
1872
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
1523
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
2035
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
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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
8503
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
8605
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
5632
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();...
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.