Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi there.

 

I think in vb6, i can use GetTickCount easily by accessing the user32.dll (hmm.. can't 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

Posted

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

  • Leaders
Posted

dont know why :-\ because they both return the exact same values , try this :

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 :

Private Declare Function GetTickCount Lib "kernel32.dll" () As Long

Private Sub Command1_Click()

MsgBox GetTickCount

End Sub

Posted
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, they're exactly the same.
Gamer extraordinaire. Programmer wannabe.
Posted

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 didn't use COM Interop!

 

Regards,

Chua Wen Ching :p

Posted

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

Posted

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

  • *Experts*
Posted

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 don't hit anything.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Hmm.. i don't intend to make it delay...

 

i can't 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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...