|
Thanks N a v a n e e t h!
My question is, I think using asyncState to transfer variable is useless as I can see from the sample, because we can wrap the asyncState into the 1st parameter of BeginInvoke method.
In another way to express, my question is in what situations does the 3rd parameter of BeginInvoke method have special function -- which we can not wrap it into the 1st parameter?
(my English is not good, please feel free to let me know if you have any questions about my description.)
regards,
George
|
|
|
|
|
George_George wrote: I think using asyncState to transfer variable is useless as I can see from the sample, because we can wrap the asyncState into the 1st parameter of BeginInvoke method.
Yeah, you can do that. C# is a flexible language. There are many ways to achieve result. If you felt that is the good design, go with that and pass null to asyncState.
George_George wrote: my question is in what situations does the 3rd parameter of BeginInvoke method have special function
When you won't be able to wrap the user state in the first parameter as you said.
|
|
|
|
|
Thanks N a v a n e e t h,
1.
There is a further question, suppose we pass a reference variable a to BeginInvoke method, then I think in the real actual asynchronous execution, the content of real object instance (which the variable is binded to) modified, correct?
2.
If it is yes to (1), then I think even before EndInvoke, in theory we can access the modified/updated content of the object instance by the reference variable, correct?
regards,
George
|
|
|
|
|
I think YES. Have you tried it ?
|
|
|
|
|
Hi N a v a n e e t h,
I asked two questions, you mean yes to both?
regards,
George
|
|
|
|
|
I am not sure as I haven't tried what you are asking. That's why I ended with a single YES. Better option is to try yourself.
|
|
|
|
|
Thanks N a v a n e e t h,
These days I am thinking and experimenting with a prototype. I want to use BeginRead and EndRead to prove what we discussed here,
http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2689514[^]
But find it is hard to retrieve in the middle of an asynchronous I/O reading. Do you have any ideas how to prototype and prove our two points discussed before?
regards,
George
|
|
|
|
|
Hi All,
are there any ways that i can generate these pieces of code by CodeDom:
public object GetAccessGetPatientCount(string firstName, string lastName)
{
using (PatientTableAdapter ta = new PatientTableAdapter())
{
// this is what i wanted, whihc has parameters
return ta.GetAccessGetPatientCount(firstName, lastName);
}
}
i am only able to generate these pieces of code:
public object GetAccessGetPatientCount(string firstName, string lastName)
{
using (PatientTableAdapter ta = new PatientTableAdapter())
{
// but i am only able to get the codes like this, which does not have parameters
return ta.GetAccessGetPatientCount;
}
}
by these c# codes:
webMethodDeclaration.Statements.Add(new CodeSnippetExpression("return ta." + methodInfo.Name));
Many thanks in advance.
Andie Du
|
|
|
|
|
AndieDu wrote: are there any ways that i can generate these pieces of code by CodeDom:
Yes, now what is the problem?
|
|
|
|
|
sorry mate, i didnt get what do you mean. My probleme has just been listed on my post. thanks a lot anyway
|
|
|
|
|
Hi there,
Am working on a Window project, i have created a User control using Infragistics Controls. i want to clear the value in the user control when i click on the "Clear" button. any advice hope to get reply soon
Regards
ybasha
|
|
|
|
|
Surely the control has a text or other property you can clear ? If their controls suck so bad that this simple operation is not clear, I suggest asking them, or on their support forums.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I created an application that converts an image to icon.. Most of my source codes are research from google.. The conversion was successful but unsatisfying results. Why? because the icon result has bad pixels and its like the color of the icon is the icon they used during windows version 3.1.. I've tried most of the source codes I have found anndd yep, all of them produced the same result. Do you have any work around on how to create a high quality version of the icon? I was wondering how GIMP does it cause GIMP has this save as ICO and the result is like the mini version of the image with complete colors.
|
|
|
|
|
Can you provide the code and even a link to examples if possible? Do you have full rights to the image? (I've seen people download images and try to convert them and they get all fudged up.)
Blog link to be reinstated at a later date.
|
|
|
|
|
I've studied most of the code and so far I think this is the main code that really converts an image source to an icon file. I removed other processes like getting the right proportion of the image during conversion.
private System.Drawing.Icon ImageToIcon(System.Drawing.Image image)
{
return System.Drawing.Icon.FromHandle(((Bitmap)image).Get Hicon());
}
And after the method has returned the icon, All I have to do now is to stream it to the computer storage device.
|
|
|
|
|
Icon.FromHandle may change the palette on you. It probably also does a quick and dirty resize. Try making a new icon sized Bitmap, getting its Graphics and then drawing your image to it using DrawImageScaled(?) with all the high quality options turned on. See what that looks like, and then see what it looks like in an icon.
|
|
|
|
|
I did. I get the image using Bitmap.. from that bitmap I made use of graphics to draw it in memory with the specific sizes.. then from the drawn icon that is from the memory I streamed it and save it to the hard disk device. Result? the same.
|
|
|
|
|
Hrmmm, make sure you set all the quality options on the Graphics object (look at interpolation) to their highest settings. Also try writing out the image to disk as a bitmap before you try to turn it into an item. You need to test if its the resize thats stuffing it up, or the icon conversion.
It might just be the case that the best the framework can do is a bicubic interpolation, and the GIMP does some extra magic for low resolutions.
|
|
|
|
|
Yup.. i did make use of the bicubic interpolation.. here's the source code i made us of
Bitmap bitmapImage = new Bitmap(textBoxImageSource.Text);
Bitmap bitmapIcon = new Bitmap(32, 32);
Graphics graphics = Graphics.FromImage(bitmapIcon);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bitmapImage, x, y, w, h);
graphics.Flush();
|
|
|
|
|
And if you write bitmapIcon out to a file it looks bad? That would indicate theres not much more you can do with the inbuilt functionality :/
I think Christian has a bunch of image processing articles here, you might have to look for something custom.
Theres also GetThumbnail(?) - but I think that has worse quality than doing a resize... not sure.
|
|
|
|
|
Has anyone ever noticed when doing custom drawing that the thicknesses of things like windows title bars thickness changes depending on windows themes?
So I was using "Display Properties"/Appearance/"Windows XP style" from the control panel and programed a custom interface and noticed that there is a 4 pixel offset for each physical docking window in the application. So I said, 'fine' and added four to the offset for each docking window including the top most window and everything lines up perfectly docked or floating. Then I thought, what if you use a classic view?
So I set "Display Properties"/Appearance/"Windows Classic style" and the menu no longer meets with the header. Now there is a staggered difference for each window type from the List View, Tab View and docking windows out to the topmost window.
I guess what my question is, aside from finding another way to do my code, how do you compensate for the windows themes changing thicknesses of things like title bars? Is there a property I should look for that will tell how thick the title bars are? Such as the difference between the location of the window and the client area?
Thanks
~Jesse
|
|
|
|
|
I used the rectangle that I calculated using user32.dll and then put the absolute positioned rectangle and converted it to a local Rectangle using ListView.RectangleToClient(Rectangle screenRectangle) and it passed back the rectangle automatically formatted.
~Jesse
|
|
|
|
|
Hi
I have an object where both files (using StreamReader/StreamWriter) and sockets (using TcpClient) are opened in the constructor. Now, I want to make sure these are cleaned up properly when the object dies/disapears out of scope, etc. My background is from C++ so I am having quite a few problems with controlling this. I tried throwing a few close() executions in the destructor, but that apparently didn't do the job. Any ideas? What is the "correct" way of solving this problem if I want all resources to be released when the object becomes irrelevant?
|
|
|
|
|
Implement IDisposable. Call Dispose on anything you use that implements IDisposable. Read the docs to get the correct Dispose pattern.
|
|
|
|
|
You can do 3 of the following things.
1. Implement IDisposable and write the Dispose Method and free all the resources you want to. You can use the Using Statement then for the block of code where you are using the object.
2. Write the Finalize method. Not a very good approach as it takes at least two cycles for GC to free up the space.
3. Implement a combination of the above 2. Example below from msdn.
public sealed class MyClass: IDisposable
{
private bool disposed = false;
public void Dispose(){
if (!disposed)
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
~MyClass() {
Dispose(false);
}
protected virtual void Dispose(bool disposing){
if(disposing){
. . .
}
. . .
}
...
}
Ahsan Ullah
Senior Software Engineer
|
|
|
|