|
Hi
The pattern is sth like this:
<br />
^-?((?<X>[0-9]{0,8})/(?<Y>[0-9]{0,15})|(?<X>[0-9]{0,8}))\*?$<br />
and I want to have the variables in their named groups as following
X=...
Y=...
I don't know how to use MatchCollection, CaptureCollection ,etc. Can anyone help me?
|
|
|
|
|
A good starting point would be MSDN help That section is extensive and pretty well written.
Let's start with a simpler pattern. Once you get it working you can make it more complex.
Suppose your pattern is smth like the following: (?<var1>\w+)
"var1" is the name of your capture
Regex r = new Regex(patter<, RegexOptions> );
MatchCollection mc = r.Matches(your_text_to_match);
if (mc.Count > 0)
{
}
Well, something along these lines anyway, I'm typing it from the memory, can't check the syntax on the home pc.
|
|
|
|
|
// get the value with: mc[i].Groups["var1"].Value;
Thanks a lot, that was so useful
modified on Wednesday, June 25, 2008 1:50 PM
|
|
|
|
|
another site that has helped me a lot in the past is
http://www.regular-expression.info/[^]
they even have a tool that you can use to quickly test your regex's
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I writea easy loop like below:
for( int i = 0 ; i < 10 ; i ++)
{
Console.WriteLine( System.DateTime.Now.Ticks );
}
the result is always is
633500324611875000
633500324611875000
633500324611875000
633500324611875000
633500324611875000
.......
Can anyone tell me why ? why it always the same ?
|
|
|
|
|
because For statement is very quick.
try it :
for (int i = 0; i < 10; i++)
{
Console.WriteLine(System.DateTime.Now.Ticks);
Thread.Sleep(1000);
}
Console.ReadKey();
Freshman
|
|
|
|
|
thanks, its export different value right now, but the result below:
633500343525625000
633500343526562500
633500343527656250
633500343528593750
633500343529687500
633500343530625000
633500343531718750
is the unit of tick is 50? I guess by the result. thanks
|
|
|
|
|
Hi,
you may find details on timing in my timers article.
|
|
|
|
|
matthew_net wrote: is the unit of tick is 50? I guess by the result. thanks
It's hardware dependent. Not all machines will tick at the same rate, so you shouldn't use it to control anything that needs to run at a fixed rate.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Ticks is only updated a few dozen times per second. If you need higher precision timers they're available. IIRC down to the millisecond level but to try and control your app at that level (as opposed to for logging) you'll pay a major price in CPU utilization since getting it hammers the kernal because windows was never intended as a realtime OS.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
thanks for your patience and kind for my pool English, I think i need to study English more hard, thanks you advice.
|
|
|
|
|
hey guys...
please consider the following code...
private int fpsCounter = 0;
private string fpsString = "0";
public myControl()
{
InitializeComponent();
animationTimer.Start();
fpsTimer.Start();
}
private void clockPanel_Paint(object sender, PaintEventArgs e)
{
fpsCounter++;
drawData(e.Graphics, clockPanel.ClientRectangle);
drawClock(e.Graphics, clockPanel.ClientRectangle);
}
private void fpsTimer_Tick(object sender, EventArgs e)
{
fpsString = fpsCounter.ToString();
fpsCounter = 0;
clockPanel.Invalidate();
}
private void animationTimer_Tick(object sender, EventArgs e)
{
calculateAndUpdateDrawingVariables();
clockPanel.Invalidate();
}
Questions
1. Will this give me an accurate frames per second reading?
2. the reading i get is +/- 100(which makes sence cuz 1000 / 10 = 100), but when the animation timer is set to 1ms the fps value is +/- 500. Is this because the image cant be drawn/calculated that fast and the image wont repaint again until previous panel.Invalidate() has not been completed?
3. quite a bit happens in calculateAndUpdateDrawingVariables(); and it runs 100times per second(animationTimer = 10ms). Any tips on what to avoid in a method like this that runs so many times to use less CPU power?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
HarveySaayman wrote: 1. Will this give me an accurate frames per second reading?
Probably not, but it will be close.
HarveySaayman wrote: 2. the reading i get is +/- 100(which makes sence cuz 1000 / 10 = 100), but when the animation timer is set to 1ms the fps value is +/- 500. Is this because the image cant be drawn/calculated that fast and the image wont repaint again until previous panel.Invalidate() has not been completed?
Your monitor is not gonna show you more than 60 times a second, going above 60 FPS is pointless (unless you are benchmarking, but then you shouldnt be painting to the screen, but a bitmap instead).
HarveySaayman wrote: 3. quite a bit happens in calculateAndUpdateDrawingVariables(); and it runs 100times per second(animationTimer = 10ms). Any tips on what to avoid in a method like this that runs so many times to use less CPU power?
Can you cache the result of the function given the same variables? If so, that would help. Else redesign you painter so that it can use a cache.
|
|
|
|
|
leppie wrote: Your monitor is not gonna show you more than 60 times a second
Not necessarily true. IF he's using an old CRT he could be running at 100+ FPS. Also there're a handful of LCDs that can run at a native 75hz as a gimic to fool noobs who think it matters like with a CRT.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
hey leppie
mayb useing the term FPS was wrong...
what this panel does in a nutshell is paint a clock(the circle, lines for hours, the numbers everything) and some data in the form of lines(start and end times) and pies(durations).
the animationTimer is used for only one of the situations this control will handel, when activated a pie(duration) will sweep in between two lines(start and stop). The idea of that is to visually represent an employees lunch break in the case that he has a "Windowed Break", lets say from 10am to 2pm to have a 30min break.
the calculateAndUpdateDrawingVariables() method basically increments the DateTime values(these later go though a timeToDegrees() method so that a getPointOnCircle() method can be called). there are also a few ifs to check that the pie isnt sweeping over its "window lines" and another if to switch a bool value that determines if its sweeping left or right.
now the reason the animation timer is 10ms is because thats a nice speed for the pie to move at.
no i have no idea how this will perform on a much slower pc like a users...
leppie wrote: Can you cache the result of the function given the same variables
i belive it can be cached because the pie sweeps left and right all the time. but how'd i do that?
any other comments given the info i just gave you?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
HarveySaayman wrote: now the reason the animation timer is 10ms is because thats a nice speed for the pie to move at.
no i have no idea how this will perform on a much slower pc like a users...
Don't use a fixed animation speed and don't rely on the fact that it will have the same speed on all computers.
Use a fixed animation callback (like 30 or 60 fps) and interpolate the actual values between the frames, this will run equally fast on all computers.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: Use a fixed animation callback
how would i do that?
Greeeg wrote: don't rely on the fact that it will have the same speed on all computers
it should, im NOT using windows.Forms.Timer BTW... as per This[^] article the multimedia timer which im using has u true(or extremely close to) 1000hz resolution unlike the normal timer or thread.sleep();
the only way i can see this going slower than it is on my dev machine is if the CPU cant calculate fast enough and somehow delay the drawing methods
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
HarveySaayman wrote: 1. Will this give me an accurate frames per second reading?
As accurate as the the timer tick gets called, but pretty close.
I wouldn't use a timer for either of the tasks, but rather fire the events myself, like this:
private void clockPanel_Paint(object sender, PaintEventArgs e)
{
fpsCounter++;
if ((DateTime.Now - lastFrame).TotalMilliseconds >= 1000)
{
fpsString = fpsCounter.ToString();
lastFrame = DateTime.Now;
framecounter = 0;
}
}
The same for the animation timer.
HarveySaayman wrote: 3. quite a bit happens in calculateAndUpdateDrawingVariables(); and it runs 100times per second(animationTimer = 10ms). Any tips on what to avoid in a method like this that runs so many times to use less CPU power?
I would reduce the timer to about 30 or 60 fps, do you really need so many updates?
Only update things that really changed inside this method, do not update any values that did not change. If you do complex math operations with matrices than for example only update the ones that changed.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: do you really need so many updates?
for the speed id like the animation to be yes...
read my 2nd post to leppie where i explained what i do more elaborately.
Greeeg wrote: If you do complex math operations
define complex? what happens is a DateTime value is converted to a value in degrees which then goes on to a GetPointOnCircle() method. The animationTick event basically adds one minute to the pies start angle, works out the sweep angle because duration is a given and then invalidates the panel so that the pie is moved to its new location.
i dont know if this is the best way to do this but its the first idea that i came up with
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
How to count the number of startup services and processes using C#. Is there a specific Win32 Class for this.
-----Have A Nice Day-----
|
|
|
|
|
RegistryKey theKey = Registry.LocalMachine.OpenSubKey
@("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
string[] theValueNamesOfKey = theKey.GetValueNames();
|
|
|
|
|
Actually I know about this registry key, but when I count the items in the Run Folder it comes out to be lesser than items listed in the startup section of the msconfig.
-----Have A Nice Day-----
|
|
|
|
|
Actually not.
If you watch msconfig carefully, you can see that it might be having a extra number of start ups, but this registry key will give you only those which are enabled.
|
|
|
|
|
Dude, the registry key you are talking about has nine entries on my computer where as the msconfig shows thirteen. And above all, they all the active. No one of them are INACIVE..
Check out my solution.
-----Have A Nice Day-----
|
|
|
|
|
I created the following method for finding out the number of all the startup processes which is exclusive of the one in the HKLM\Software\Microsoft\CurrentVersion\Run. Here it goes.
public int getStartupProcessCount()
{
RegistryKey theKeyHKLM = Registry.LocalMachine.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Run");
string[] theValueNamesOfKeyHKLM = theKeyHKLM.GetValueNames();
RegistryKey theKeyHKCU = Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Run");
string[] theValueNamesOfKeyHKCU = theKeyHKCU.GetValueNames();
string val;
string dName;
int indexVal;
int countStartupProcessess;
string[] allVal = new string[theValueNamesOfKeyHKCU.Length + theValueNamesOfKeyHKLM.Length];
theValueNamesOfKeyHKLM.CopyTo(allVal, 0);
theValueNamesOfKeyHKCU.CopyTo(allVal, theValueNamesOfKeyHKLM.Length);
countStartupProcessess = allVal.Length;
string[] directories = Directory.GetDirectories("C:\\Documents and Settings");
foreach (string d in directories)
{
foreach(string d1 in Directory.GetDirectories(d))
{
indexVal = d1.LastIndexOf("\\");
dName = d1.Substring(indexVal+1, d1.Length - (indexVal+1));
if (dName.ToUpper() == "START MENU")
{
foreach (string d2 in Directory.GetDirectories(d1))
{
foreach (string d3 in Directory.GetDirectories(d2))
{
indexVal = d3.LastIndexOf("\\");
dName = d3.Substring(indexVal + 1, d3.Length - (indexVal + 1));
if (dName.ToUpper().Trim() == "STARTUP")
{
foreach (string f in Directory.GetFiles(d3))
{
indexVal = f.LastIndexOf(".");
dName = f.Substring(indexVal + 1, f.Length - (indexVal + 1));
if (dName.ToUpper() == "LNK" && dName.ToUpper() != "INI")
countStartupProcessess++;
}
}
}
}
}
}
}
return countStartupProcessess;
}
-----Have A Nice Day-----
|
|
|
|