chuawenching Posted July 27, 2003 Posted July 27, 2003 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 Quote
Leaders dynamic_sysop Posted July 27, 2003 Leaders Posted July 27, 2003 private void button4_Click(object sender, System.EventArgs e) { MessageBox.Show(System.Environment.TickCount.ToString()); } :) Quote
chuawenching Posted July 27, 2003 Author Posted July 27, 2003 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 Quote
Leaders dynamic_sysop Posted July 27, 2003 Leaders Posted July 27, 2003 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 Quote
wyrd Posted July 27, 2003 Posted July 27, 2003 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. Quote Gamer extraordinaire. Programmer wannabe.
*Gurus* Derek Stone Posted July 27, 2003 *Gurus* Posted July 27, 2003 Considering Environment.GetTickCount() directly calls the Win32 API GetTickCount I would hope their output is identical. Quote Posting Guidelines
*Experts* Volte Posted July 27, 2003 *Experts* Posted July 27, 2003 You'll need to use [api]QueryPerformanceCounter[/api] for the highest precision. Quote
chuawenching Posted July 29, 2003 Author Posted July 29, 2003 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 Quote
Leaders dynamic_sysop Posted July 29, 2003 Leaders Posted July 29, 2003 nope just use System.Environment.TickCount no need for dll import :) Quote
chuawenching Posted July 29, 2003 Author Posted July 29, 2003 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 Quote
*Experts* Volte Posted July 29, 2003 *Experts* Posted July 29, 2003 Paste your code. I assure you it is not a bug in C#. Quote
chuawenching Posted July 29, 2003 Author Posted July 29, 2003 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 Quote
*Experts* Nerseus Posted July 31, 2003 *Experts* Posted July 31, 2003 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 Quote "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
*Gurus* Derek Stone Posted July 31, 2003 *Gurus* Posted July 31, 2003 There really isn't any apparent reason to use GetTickCount in the code example you've provided. Instead, render the pictures in a loop. If you want a noticeable delay use Thread.Sleep() after each iteration. Quote Posting Guidelines
chuawenching Posted July 31, 2003 Author Posted July 31, 2003 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 Quote
Recommended Posts