VB6 GetTickCount() in C#?

chuawenching

Well-known member
Joined
Jul 26, 2003
Messages
66
Hi there.

I think in vb6, i can use GetTickCount easily by accessing the user32.dll (hmm.. cant remember what is the dll name, but something like that)

Is there any code in the System.namespaces which i can get the exactly same values for GetTickCount() in c#?

I heard timer return seconds rather than miliseconds...

Any help?

Thanks.

Regards,
Chua Wen Ching :p
 
Hi there. I did try that method.

But the output is a bit different with vb6 GetTickCount()

It looks like VB6 version is more faster and more accurate... (corrent me if i am wrong)

Anyway thanks for the reply.

Regards,
Chua Wen Ching :p
 
dont know why :-\ because they both return the exact same values , try this :
Code:
using System.Runtime.InteropServices;
/// top of your code window.
//////////////////////////////////////

[DllImport("kernel32.dll")]
public static extern int GetTickCount();
/// below windows generated code^^^^
//////////////////////////////////////

private void button1_Click(object sender, System.EventArgs e)
{
            MessageBox.Show(System.Environment.TickCount.ToString() + "  " + GetTickCount().ToString());
}

they both give the same values :)
as does this vb6 example :
Code:
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long

Private Sub Command1_Click()

MsgBox GetTickCount

End Sub
 
I just did some minor testing on both the API function GetTickCount() and the .NET Environment.TickCount. There was no noticeable difference. As dynamic_sysop said, theyre exactly the same.
 
Considering Environment.GetTickCount() directly calls the Win32 API GetTickCount I would hope their output is identical.
 
Youll need to use [api]QueryPerformanceCounter[/api] for the highest precision.
 
Hmm... just wonder

if i use this:

System.Environment.TickCount

Do i need to code this too:

[DllImport("kernel32.dll")]
Public Static extern int GetTickCount();

--> I remember i didnt use COM Interop!

Regards,
Chua Wen Ching :p
 
Hmm.. funny!

I am doing a 3d stimulation. I did that in vb6 and now want to port into c#.

with vb6, gettickcount, it works smoothly..

it was suppose to renders 20 pics over and over again to see the smooth effects.

but in c#, after 1 second, it will stop, and the effects disappear. After another second, it works, and stop again.

Had any idea why it happen?

I think it is C# TickCount problem!

Anyway thanks.

Regards,
Chua Wen Ching :p
 
Hmm.. ok.. let me find!

C# (compile ok, but running that time looks funny)
=====================================

float lastTick;

private float GetTickCount() // float or int - makes no difference
{
return System.Environment.TickCount;
}

if ((GetTickCount() - lastTick) >= 25)
{
....
lastTick = GetTickCount(();
}

I think i left the vb6 codes at home. I am now in working place.

Any help?

Regards,
Chua Wen Ching :p
 
We really need to see the rest of the code... what you have appears to be standard for doing something every 25 milliseconds. But considering that the precision is 15 or 16, you may have a lot of cycles where you dont hit anything.

-Nerseus
 
There really isnt any apparent reason to use GetTickCount in the code example youve provided. Instead, render the pictures in a loop. If you want a noticeable delay use Thread.Sleep() after each iteration.
 
Hmm.. i dont intend to make it delay...

i cant release the codes, it is a directx and it is partial of my game development.. sorry!

ANyway thanks for the help...

Regards,
Chua Wen Ching :p
 
Back
Top