|
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.
|
|
|
|
|
Nick Parker wrote:
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.
This is what ive always stuck to as well, glad im not alone in my thinking on this.
|
|
|
|
|
Hello all
how can i convert an int32 to hexadecimal and string to hexadecimal?
i am working at C#
Thanks alot
|
|
|
|
|
Not too sure what your question means but to display an int in Hex, you can use the ToString() method as below. As for converting a string to Hex, I don't quite understand what you mean.
int convertMe = 102;
string converted = convertMe.ToString("X");
|
|
|
|
|
If you need to convert a string with hexdecimal presentation to int look at the Convert.ToInt32 method.
|
|
|
|
|
|
Hi
maybe i am not making any sense..i am creating a HTML file on runtime and opening it in a Webbrowser control,the html also have links..instead of assigning html or other http file link in SRC tag,i want to call my c# function which grab the particular text from webbrowser control and pass it in some C# function,for instance,my HTML have links
1)Apple 2)Oranges,when i click Apple,then it calls MessageBox with text "Apple" etc..is it possible?how can I inject some code to call c# based routines
Thanks
|
|
|
|
|
I can think of two possible solutions to your problem.
The first is to hook-up an event handler for the browser control's BeforeNavigate2 event. You can then use this to parse special commands passed in the SRC attribute and execute particular methods. An example is shown below.
HTML:
Calls Host Form's MyCommand Method
C#:
private void WebBrowser_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
// Determine if this is a proper url or a command
if (((string)e.uRL).IndexOf("command:") != -1)
{
// Call the appropriate function for the command
switch (((string)e.uRL).Replace("command:", ""))
{
case "mycommand":
this.MyCommand();
break;
}
// Stop the browser from performing the navigation
e.cancel = true;
}
}
The other method is to hook up some event sinks to capture the DHTML events.
Hope this helps.
Aaron
|
|
|
|
|
|
I hope my already 2 day search ends here !
This is what I want to be able to do: existing app A generates sql-qeurys and sends these as strings to app B (application to develop). These querys are send to a database server and the result is put into two different files (one file with result data layout and the other with actual result data).
Now app B must return a struct with information about these files(location etc) and some additional information to app A. App A reads the files and presents the information to the user.
My question now is: how do I send data (using structs with strings, integers etc) between two applications?
My intention is to use Window Messages for this task using SendMessage / WM_COPYDATA. I have not been able to find an example which made it (crystal)clear for me, maybe someone can help me tackle this problem.
Or do you think this approach is not the good one, please tell me!
Thanks in advance,
Darth
I can't get no satisfaction.
|
|
|
|
|
You could just serialize the sturcture and send it as a byte array from app B over a socket to app A and de-serialize it. This way App A and B do not neccessarily need to be on the same computer. Just an idea.
|
|
|
|