|
hi heath
heath you are correct. we can use asynchronous when we are not expecting the result to the consecutive operation. here the senario is same. only thing is i need to refresh table just before user closes the application or save the application. if i put this much code block in save,then it will work. but user may save different time while working with the application. So all time it will execute asynchronous code block. doing this is won't make too very sence here.Here i want to refresh only once with final updation. Amount of data to refresh is huge(minimum say 5000 record(15 feilds)). So i don't want to disturb user for his all saving operation.
You told me asynchronous is not a perfect match for this senario. That is correct and i know it very well. But heath, if i want to do synchronous (normal) style of record insertion it will take 30 to 40 seconds to complete. But if i go for asynchronous(as per my logic) it will take only 4 to 5 seconds.
heath tell me which other way i can adopt for this sort of situation except synchronous to make my operation duration 4 to 5 second.
thanks
sreejith
********************
S r e e j i t h N a i r
Bangalore - India
********************
|
|
|
|
|
The amount of time it takes to update your database is rather static (might differ a little due to various conditions). It's just that here your asynchronous call is executed and execution is returned immediately to the caller (your Form.Closing handler).
If this is not your main application Form , add the code to update the database elsewhere (perhaps on the original caller), as well as a way to get a deep copy of the data from the Form that is closing. Then execute the method asynchronously and the effect of the Form closing won't matter.
Also, for this Form - if not the main application form (i.e., that which is directly or indirectly passed to Application.Run ) - if you use Form.Show , you don't need to dispose of the Form so don't - the async operation should run even though the form is hidden (depending on how you're accessing data that was input into the form). If you're using ShowDialog , then you're supposed to dispose your Form once you get what you need from it (otherwise you'll have a memory leak). In this case, you're back to what I said previous: you have to block at some point and wait for that async operation to complete with having done little else (i.e., the form was hidden), so there's really no point to using asynchronous operations, here.
A better design is to prompt the user to save before closing and take your time. This is what most other applications do. Open Microsoft Word, type a character or so and close the application - your prompted. Do the same with Notepad, Excel, AutoCAD, etc. Why not take this approach? At least the user no knows what's going on. Add that with a ProgressBar (perhaps a step for each record updated, depending on how you update your data source) and you'll have a much more user-friendly application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
Heath i have a doubt. When we run an application i mean a standalone .exe. is this perticular exe is comming in one appdomine or not ?
********************
S r e e j i t h N a i r
Bangalore - India
********************
|
|
|
|
|
An EXE - if invoked by the executable loader - has at least one AppDomain in which it's loaded an run. I say that because an EXE .NET assembly can be loaded just like a DLL (the metadata is loaded, regardless of the PE/COFF executable).
It can create additional AppDomains, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So how can i know how many threads are there in my appdomin without main thread.
If it is possible how will i know whether that perticular thread status.
sorry for this disturb
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Process.GetCurrentProcess().Threads.Count
I don't see what good that will do, though. You're code isn't the only code starting threads. Windows applications use many threads in the background as needed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
Heath i have a doubt. When we run an application i mean a standalone .exe. is this perticular exe is comming in one appdomin or not ?
********************
S r e e j i t h N a i r
Bangalore - India
********************
|
|
|
|
|
There are only a few reasons why anyone should embrace asycronous response patterns and this doesn't appear to be one of them. You should design the batch processing into the SQL server instead of in the client application.
You should avoid it if possible because it makes problems more complex. Trying to do this "mixed mode" thing becomes a nightmare. You should either keep everything syncronized or asycronous because bridging between causes all sorts of fun issues (like race conditions and deadlocks). Simple tasks like deleting rows become much harder. If you want to delete, you must syncronize against the asycronous handle you setup elsewhere to do insertions. If you want to exit you have to syncronize against the asycronous handle you setup elsewhere to do insertions. Heck even adding rows you will have to be careful.
Asycronous programming is not for the faint of heart which is why I constantly recommend against using it unless you have to. The point of a SQL server is to keep transactions sane and syncronized. Why thawart this?
|
|
|
|
|
Hi,
Is it possible to port the code developed in C# on to a Solaris machine??
Is there any cross platform product that makes it possible??
If somebody has idea how to do it, please reply.
Regards,
Satya
|
|
|
|
|
Mono[^]
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Hi,
I want to use C# features and port it to Sun Platform, is this possible??
Regards,
Satya
|
|
|
|
|
|
Hy everyone!
Yeah, shame on me, but it seems I actually do have a blackout , although this should be something of C#s basics:
I do have two clases
<br />
public class Key<br />
{<br />
public int keyId;<br />
public string telephoneNo;<br />
}<br />
public class Telephone<br />
{<br />
public Key[] keys;<br />
public string telephoneId;<br />
}<br />
o.k. that's it. But now I do want to create an array of Telephoneobjects (Lentgth 1) - which of course contains the telephoneId field - which contains an array of Keyobjects - which of course contains the keyId and the telephoneNo.
This finally should allow the following assignment for example
<br />
mynumbers[0].telephoneId="12345";<br />
mynumbers[0].keys[0].keyId=12;<br />
mynumbers[0].telephoneNo="12345";<br />
Yes, I know I should have known myself but I guess I do have kind of blackout at the moment!
Thanks for your patience for helping to get rid of my blackout!
Stephan.
|
|
|
|
|
Telephone[] telephones = new Telephone[1];
telephones[0] = new Telephone();
Also, you should not declare fields as public , it violates the encapsulation rules in Object Oriented design. You should wrap the behaviour in properies instead - this allows you to change the internal structure of the class without modifying the external interfaces.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
oh well, then my blackout was thinking it was wrong what I was doing!
Thanks for your help!
Stephan.
|
|
|
|
|
Does anyone knows how to write a c# program to convert a *.wav ( wave ) file to a midi file...?
|
|
|
|
|
Short answer: I don't know.
Long answer:
Wave files are "recordings" of sounds using digital samples of the audio waveform amplitude. At the risk of oversimplifying, they're essentially a series of numbers, and if you draw a graph of those numbers you'll see a waveform that looks just like the sound would look on an oscilliscope.
MIDI files consist of instructions for synthesized musical instruments, such as "press the C key on the piano softly, wait a quarter of a second, then release it".
A wav to midi conversion program would need to be able to look at a waveform and determine not only what note is being played, but how loudly and by which type of instrument, and to distinguish the sounds of multiple instruments playing at the same time, potentially mixed with sound effects, vocals, etc., any of which may not be able to be represented in MIDI format.
Despite those difficulties such programs do exist. Sort of. Search for "convert wav to midi" on Google to find some of them and to read more about this complicated subject.
This doesn't answer your question, though, which is how to do it in C#. I don't know the answer to that.
|
|
|
|
|
Why constructors don't return values ??
|
|
|
|
|
Because constructors are called when a new class is created, and therefore what is returned to the caller is a new instance of the class.
"A people that values its privileges above its principles soon loses both." -- Dwight D. Eisenhower
|
|
|
|
|
As an extra to the previous answer, if you want to inicate that something in the constructor did not work as expected, throw an exception, that or provide an extra initialisation function for use after the object was constructed.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
i draw some rectangles and lines into the the panel object. but how can i save the content in the panel object to a bitmap file ?
thanks....:
|
|
|
|
|
If you want to keep what you've drawn to your panel, then I guess you'll have to take a different approach altogether.
Am I right that you're calling myPanel.CreateGraphics() and then use this Graphics object for painting? In this case, the actions are not recorded anywhere and your panel will be blank after the next paint event it receives (try hiding your panel behind another window and then restoring it...).
I think you should use a Bitmap from the start and paint onto this Bitmap using a Graphics object retrieved by Graphics.FromImage() .
In the paint event handler of your panel you paint the bitmap.
That way you can also call myBitmap.Save(...) to save the contents of the bitmap.
Regards,
mav
|
|
|
|
|
What 'mav' said will work, but there's several problems with his approach. If you draw on a Graphics object that you obtained from Control.CreateGraphics , your elements will be drawn. But if the form needs repainting (perhaps it was covered up by another form), they won't be redrawn. You need to perform your drawing in an override of OnPaint (which is passed a PaintEventArgs that has a Graphics property that you should use for painting).
In order to be able to save that same code to a Bitmap class and then to a file, you'll want to modularize your code like so:
private void PaintRectangles(Graphics g)
{
g.DrawRectangle(...);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
PaintRectangles(e.Graphics);
}
private void saveBtn_Click(object sender, EventArgs e)
{
using (Bitmap bmp = new Bitmap(panel1.Size.Width,
panel1.Size.Height))
{
using (Graphics g = Graphics.FromImage(bmp))
{
PaintRectangles(g);
}
bmp.Save("filename.png", ImageFormat.Png);
}
} Now you've encapsulated your rectangle drawing code into a single method that can draw onto any Graphics object, including the form or panel itself (this is only an example, mind you) or a Bitmap . The using statements above make sure that both the Bitmap and Graphics objects are disposed (very important, otherwise memory may not be freed when necessary and unmanaged objects will linger, causing memory leaks) even if an exception is thrown.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm improving the GUI of my demo program. There are some controls in the UI, like textbox and numericUpDown etc. I just want to highlight the text (fullly select the text) when I tabbing them.
now, I just using the Control's Enter event handler for each control, and then do selection inside its function.
I felt quite inconvenient, especially, when using numericUpDown, I need to do selection by using this command :
numericUpDown1.Select(0, numericUpDown1.Value.ToString().Length);
so, Is there any easy way to do this?
thanks
|
|
|
|
|
Some of the controls such as TextBox have .SelectAll() method but some like numericUpDown don't. But if you want that behaivor for all of your controls you could go with mass selection of them all and then handling their's .Enter event.
<br />
Control[] GetAllControls() <br />
{<br />
ArrayList list = new ArrayList();<br />
GetAllControls(Controls, list);<br />
return (Control[])list.ToArray(typeof(Control));<br />
}<br />
void GetAllControls(Control.ControlCollection controls, ArrayList list)<br />
{<br />
foreach(Control control in controls) {<br />
if(control.HasChildren) GetAllControls(control.Controls, list);<br />
list.Add(control);<br />
}<br />
}<br />
<br />
void Form_Load(object sender, System.EventArgs e)<br />
{<br />
foreach (Control c in GetAllControls())<br />
c.Enter += new EventHandler(c_Enter);<br />
}<br />
<br />
void c_Enter(object sender, EventArgs e)<br />
{<br />
if (c is TextBox)<br />
((TextBox)c).Select(0, c.Text.Length);<br />
}<br />
To make it easier you could detect Base classes (for TextBox it is BaseTextBox)... if someone has better solution please correct me...
|
|
|
|