|
ignore above message:
<a.*>(.*+)not any or
what "expressions" can i use to do the above ..cheers
|
|
|
|
|
You forgot to turn off HTML tags, so I can't see your correction....
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
<a.*>((.*+)not any <b>or</b>)</a>
what "expressions" can i use to do the above
cheers
|
|
|
|
|
Hi Folks
I've got a seperate thread running in my application, that is processing a tree search. This works fine.
My OnPaint event draws the image generated by the enviroment by passing in the graphics handle of the window. The invalidated region since the previous onPaint call, is requested, and then the screen is invalidated. This also works fine.
My problem comes when right clicking or double clicking on the window in the task bar when hidden, or clicking on it while visible to minimise it, which throws an ArgumentException, with 'Invalid Parameter Used'.
As my derived thread does not call any of the windows components, and simply works on a recursive stack function which manipulates an enviroment. So, as far as I can see the threads are completely seperate and do not rely on each other for information. So i do not know why these errors are being raised.
Can anyone explain why this is happening?
Cheers
Cat
|
|
|
|
|
Catalyst,
Please post some sample code. That would help disabiguate what you mean by "tree" and "environment".
If I understand correctly, it sounds like the threat is still interacting with OnPaint . Like nearly every other member of a Control class, painting must be done - unless double buffered - in the same thread on which the control was created using Control.Invoke . The OnPaint is actually a message handler for the Windows WM_PAINT message. When you force and update from a separate thread this message may be sent to the wrong thread and would cause problems that Control.Invoke solves by making sure messages (which are event sent to set text, like setting TextBox.Text ) are sent on the right thread.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
All the graphics are double buffered on a seperate thread.
The OnPaint event of the control calls the enviroment with a graphics handler:
My enviroment contains the following code:
<br />
public void RenderEnviroment(Graphics g, int width, int height)<br />
{<br />
Image i = new Bitmap(width,height);<br />
Graphics gfx = Graphics.FromImage(i);<br />
<br />
int buffer = 5;<br />
gfx.FillRectangle(new SolidBrush(Color.Black),0,0,buffer+(buffer+100)*WIDTH, buffer+(buffer+100)*HEIGHT);<br />
<br />
for (int x=1;x<WIDTH-1;x++)<br />
{<br />
for(int y=1;y<HEIGHT-1;y++)<br />
{<br />
Tile t = this.g_Enviroment[x,y];<br />
if (t != null)<br />
gfx.DrawImage(t.TileImage,buffer + (100*(x-1)) + (buffer*(x-1)),buffer + (100*(y-1)) + (buffer*(y-1)));<br />
}<br />
}<br />
<br />
gfx.DrawString("Permutations Tested: " + permChecked.ToString(),<br />
new Font(FontFamily.GenericMonospace,14),<br />
new SolidBrush(Color.White),<br />
buffer,height-100);<br />
<br />
g.DrawImage(i,0,0);<br />
}<br />
This is called from the OnPaint method of my form, where env is a gloval Enviroment variable:
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
env.RenderEnviroment(e.Graphics,this.ClientRectangle.Width,this.ClientRectangle.Height);<br />
Thread.Sleep(100);<br />
<br />
Region r = env.GetInvalidatedRegion();<br />
this.Invalidate(r);<br />
}<br />
The Tree is largely irellevant, as it runs on a seperate thread and does not interact with the form at any point. Enviroment contains a 2D grid, which is modified by the spawned thread, but is only read by the Painting thread.
Hope that helps
Cata
|
|
|
|
|
Never block the painting handler. This can severely cause the application to hang since painting messages are sent almost continually. So long as RenderEnvironment doesn't do anything in a separate thread, execution is blocked until it's done then GetInvalidatedRegion will run. The Thread.Sleep(100) should not be necessary.
Even though you're not modifying the control you are modifying the 2D grid (I assume a multi-dimensional array) in another thread. If OnPaint or it's callers access that while it's being written this could very easily cause a problem. Use an object (same reference; typically a static reference property will do) to lock between writing and reading the grid.
Depending on how often it's written or read, you might consider even using a ReaderWriterLock , which is documented in the .NET Framework SDK. The important thing is that something isn't reading the grid while something else (the other thread) is writing it.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Heath,
Cheers for the reply. I changed the 2D array to volatile, as i only have 1 thread writing to it 3.5 million times a second, and it's read from only 60, an exactly up to date reading is not essential. It seems to have speeded the program up slightly.
I added a try / catch block on the on the RenderEnviroment, and discovered that when the program is minimised, the client area that I was using to base my rectangle off was 0,0, which threw an error when trying to construct a bitmap, the error that was thrown without the try block always reverted back to the Main method of the application.
I should have thought of it earlier, but it's sorted the problem out now.
Cheers
Tris
|
|
|
|
|
It would seem that you're forcing a repaint, then. Windows will send a visible window the WM_PAINT message (which in Windows Forms translates to the OnPaint handler, which fires the Paint event) along with the clipping rectangle that needs to be redrawn (redrawing only this rectangle or just objects that intersect it yields better performance for your application). If you force an update you will run into problems like you are now.
I recommend not forcing an update, but simply invalidate. Windows will send a WM_PAINT message ASAP if your window is visible. If it's not visible, then there's no point to send the message and you won't run into problems that you had when the app was minimized.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Well, I do have a problem then.
I don't want the screen to refresh continuously without pause, because this will pull processor time from my other thread which is more important. My display is purely so I can see what is going on.
If i don't force the on paint, the screen will only ever refresh if i do something to it manualy, like resize or min/maximise. I see no point in running a seperate thread that invalidates my screen 15-20 times a second, because it will simply eat more cpu time.
Can you suggest another solution to this problem?
|
|
|
|
|
When the application is idle or you ask the window manager to update the application, the invalidate region for the window for which painting is requested is redrawn (unless the application ignore the clipping region and redraws everything). This is key to having an efficient control: do not draw the whole thing.
Invalidate the region you need (perhaps the entire control; it depends on your requirements) and let the application update the window by placing the WM_PAINT message in the message queue. Set Thread.IsBackground to true and Thread.Priority to a lower priority so that your main application thread can concentrate on painting (or give it a higher priority).
At the very least, you must force the repaint in the right thread but shouldn't block by using Thread.Sleep because enough requests fast enough could mean that the message queue grows large and your visible graph won't match your in-memory graph.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Currently my GetInvalidatedRegion() method returns the entire area, but it's not fully implemented yet, it needs a bit of work so that it can return the area that changed since the last call to the method.
I'm not entirely sure what you're saying here though.
Are you saying spawn a new thread with lower priority to loop through Invalidating the appropriate region?
Or are you saying lower the thread priority in the OnPaint method so that it won't chew up as much juice?
I'm guessing it's not the second as that repaints once every 10 seconds.
My main application thread is the one that launches the form, and inside that it creates a WorldEnviroment object which it sets running.
C
|
|
|
|
|
Give priority to the main thread so that painting is done more often. You can also make sure your invalidated region is updated by calling Control.Update in the thread in which the control was created (your main application thread). Sleeping, again, will just mean that messages keep queuing up instead of getting handled ASAP.
Think about this: you tell the control to redraw about once every 50ms, but you sleep for 100ms. That means that for each redraw roughly 2 paint messages have been queued (taking into account how long it takes to paint). That sure adds up in a short amount of time and then either your visual graph and object graph will be out of sync, or your application's performance will be hindered since the queue will be filled with paint messages and may not process user input messages, for example, as quickly. You really need to benchmark your application to check for performance problems.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hiiii,
i send datagrams through internet using udpclient class defined in .net namespace, but it never reach it's destenation.
i know that udp is unreliable protocol. but not even one packet arrives!!!!!!!!!!!
marcoryos
|
|
|
|
|
|
/********************************/
UDPClient Client=new UdpClient();
Client.Bind(new IPEndPoint(Dns.GetHostByName(Dns.GetHostName()).AddressList[0],5000);
byte[]result;
MemoryStream stream=new MemoryStream();
foreach(UserInfo info in GroupUsers)
{
if(compare(info,MyClientInfo))
continue;
seachMessage.Destenation=info;
SerialSearch.Serialize(stream,seachMessage);
Client.Send(stream.GetBuffer(),(int)stream.Length,new IPEndPoint(info.IP,info.port));
stream=new MemoryStream();
}
IPEndPoint point=new IPEndPoint(IPAddress.Any,0);
while(true)
{
try
{
result=Client.Receive(ref point);
q.Enqueue(result);
}
catch(SocketException ex)
{
break;
}
/************************************/
that's was part of my code. it works fine on lAN, by the way UDPClient i Inherited from UdpClient just to use client protected member to set socket timeout so it won't block forever,and i set it in Constructor. am afraid that the problem from UDP datagram size. becouse SearchMessage object after serialization about 2k
thanx so much for your time.
marcoryos
|
|
|
|
|
You're not instantiating a UDPClient , however, but a UpdClient . You're declared type isn't so much important as what you instantiate. If you want your overridden protected member - of even your constructor - to be called you must instantiate your class:
UDPClient client = new UDPClient();
UdpClient client = new UDPClient(); The inheritance model means that your overridden method or constructor will be called instead of your declaring type (UdpClient ). That may solve your problem if I understand your problem correctly.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Can I use the XMLSerializer to serializer a collection of collections?
I have a TaskCollection class that is a collection of Tasks. My task class has an instance of a RecordCollection class that is a collection of Records.
So it goes TaskCollection -> Task -> RecordCollection -> Record.
I was able to XMLSerialize the TaskCollection before I added a RecordCollection to my Task class. Why can't I serialize a collection of a class that has a collection of another class?
|
|
|
|
|
Doh! I had my collection inside my Task class setup as an XMLAttribute. I removed the syntax and it worked.
|
|
|
|
|
I have a situation where I have a Crystal Report pulling data from a database and I want to be able to check a couple of things in the report to determine that it should be printed. Is there a way to pull data out of some fields in the report for verification before printing, or do I have to do a seperate database query in C# to validate such info?
If anybody could help me, it'd be appreciated. I've checked MSDN, BusinessObjects, and all the programming sites I can think of to no avail.
--In a world without fences, who needs Gates?
|
|
|
|
|
SignMan359,
An alternative would be to get a DataSet yourself using a DataAdapter derivative (like a SqlDataAdapter ) and use that to populate the report by calling ReportDocument.SetDataSource . When designing your report, you can bind against an strongly typed ADO.NET DataSet . Read Reporting off ADO.NET Datasets[^] for details.
This would allow you, then, to get the DataSet , check any rows in tables you want, then decide whether or not to instantiate your ReportDocument -derivative that you've designed, set the data source, and display it. This way you can also control whether the report and report viewer are even instantiated in the first place.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hi
i'm new
when is it best to use setProperty(val) to set a property and when is it best to use property = val?
thanks
|
|
|
|
|
AFAIK it's pretty much the same (IIRC property's getter and setter are actually ordinary functions, whole property concept is just "syntax sugar" - am I right? ). I think it's matter of style.. would you use person.Age or person.getAge() ? I'd use the first one...
p.s if somebody knows guidelines or something about when to use property and when functions, lemme know!
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
I think its a matter of your personal taste.
I always use properties when its just about setting values. The only situation where I make an explicit setter method is when the setter should have another visiblity than the getter. But this will be obsolete with the next framework version.
|
|
|
|
|
thepersonof wrote:
when is it best to use setProperty(val) to set a property and when is it best to use property = val?
If you don't have any specific logic that needs to be applied to simply set the value of the private variable it is best to use a property. If you need to perform some specific conditional logic, etc. when setting the value typically would use a method.
|
|
|
|
|