|
Thank you for your quick response.
It solved my problem. But i didn't get the actual thing. If you have time, please enlighten me in this area, by giving some more info.
Application.exit() or the start form.close() , are both of them equal?
If we set isbackground property to true. after the form.close(), all the threads of the application will automatically aborted?
M.V.Ravikumar
|
|
|
|
|
Ravikumar_mv wrote:
Application.exit() or the start form.close() , are both of them equal?
No they are not! The Application.Exit method informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed. Whereas the Form.Close only closes a form, which doesn't necessarily result in termination of your application.
Also note what the documentation for both methods states:
"CAUTION The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method."
Ravikumar_mv wrote:
If we set isbackground property to true. after the form.close(), all the threads of the application will automatically aborted?
Yes they get automatically aborted. Documentation for the IsBackground property says:
"Once all foreground threads belonging to a process have terminated, the common language runtime ends the process by invoking Abort on any background threads that are still alive."
www.troschuetz.de
|
|
|
|
|
Ravikumar_mv wrote:
If we set isbackground property to true. after the form.close(), all the threads of the application will automatically aborted?
It is best to set the .IsBackground property to true BEFORE you start the thread, not when you end it.
Also, writing your threads so that they can exit gracefully. This means handling some kind of flag or exception that signals the thread to close any open resources it has before it quits. Just doing a threadObject.Abort() on it will terminate the thread at just about any point, not necessarily when it's safe to do so.
For an example of this, see this[^] link on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you for ur quick response. It solved my problem.
Sorry for my late response.
M.V.Ravikumar.
|
|
|
|
|
Hi,
I just can export table structure to excel. No data found. Pls help.
here is my code :
......
this.sqlDataAdapter.Fill(this.dsTables, "testTable");
DataGrid dg = new DataGrid();
dg.DataSource = this.dsTables.Tables["testTable"];
dg.DataBind();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.enableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
dg.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
Thanks
Wilson
|
|
|
|
|
This question really belongs in the ASP.NET forum. It really has nothing to do with C#, even though the codebehind is written in it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Have you tried debugging it? Did the dsTables DataSet contain any data? Did you remember to use the SqlDataAdapter.TableMappings to make sure that the first result set ("Table") matched up with "testTable"? The SqlDataAdapter.SelectCommand may have in fact retrieved data but unless the table mappings are set up correctly, the "testTable" DataTable won't contain any data, so nothing but a skeleton table would be output to the HtmlTextWriter .
Step through the code and check the state of the variables with each relevent step (like after you Fill the DataSet , after you call db.DataBind , etc.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
when i drop a DataAdapter on the form and use "generate dataset" command(by right clicking the dataadapter on the form), this error display :
there were problems generating winapplication1.DataSet1. To resolve this problem , build the project, fix any errors , and then generate the dataset again.
then i creat another application and another database but this message display again.(when i build project, has not error!)
I also reinstall my VS.NET completely, but i have problem with this error too.
thanks.
|
|
|
|
|
Reinstalling all that was a complete waste of time, obviously. There's nothing wrong with the development environment.
More than likely, the DataAdapter has an incorrect connection string in it and it can't connect to the database. I know your going to say, "But the string was generated by Visual Studio in the designer!" So what, it doesn't make it right. What your going to have to do is simplify the connection string and make sure that the options are set correctly. Using the designer to generate the database stuff is also an inefficient way of doing it. Your better off coding the data stuff by hand. That way, you'll have much better control over it and a much easier time troubleshooting any problems. You'll also learn a heck of a lot more, faster, than if you were to let the designer generate the code for you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Reinstalling VS.NET is not a viable solution; it's not the problem - the .NET Framework is the problem, and VS.NET != .NET. Almost all the designers used by VS.NET is actually defined in the .NET base class libraries (BCL).
Did you actually follow the error message? Build and look for warnings and errors. Fix them, close the designer, and re-open it. This usually fixes the problem. Restarting VS.NET can also help. Creating a new application won't help - the problem is in the first application.
Another solution is to build the typed DataSet first. In VS.NET, right-click on your project (or a sub-folder) and select Add, Add New Item. Select "DataSet", give it a name, and click OK. Add top-level elements (as tables) and their elements (as fields). When you drag and drop a DataAdapter -derivative to your control designer and configure it, you can use a designer to map what would be selected into the typed DataSet you just created. This also gives you more control over column constraints, relationships (which enforces foreign key constraints and provides cascading capabilities), etc.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hi to all the printing experts out there ,
I have to print an image of a PCB(printed circuit board). I got an image of the PCB and it's real width and height. What is the best way to print this image in it's real size?
I haven't done any printing in C# yet; except using Crystal Reports. But I think that Crystal Reports won't be able to print the image correctly, if it's real size is larger than one page.
Best Regards
Bernd R.
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
Crystal Reports really isn't suited to this purpose anyway, and it would be overkill to deploy (there's several Merge Modules (if you're using a Windows Installer package) to distribute and you need a developer key).
There's three options when printing anything (including fix-width paragraphs for text): reduce the size of the object; crop the object; display the object on multiple pages.
Obviously the first two options are out since you care about the true size of the PCB and a partial PCB wouldn't be much help.
When you handle the PrintPage event of the PrintDocument , you can query the printable portion of that page by using the PrintPageEventArgs.MarginBounds , which is size of the page minus the margins for each side (these can be changed on a page-by-page basis using the PrintDocument.QueryPageSettings , but the printer has to support that and have the right paper loaded into trays or expect is correctly using a manual feed). When you draw the image, use the PrintPageEventArgs.Graphics property and call DrawImage initially using coordinates of Point(0, 0)</cod> and <code>PrintEventArgs.MarginBounds.Size .
If you do want to scale the image, use a different overload for Graphics.DrawImage call with the appropriate arguments. Several of these will scale the image.
Be sure to read the class documentation for the PrintDocument.PrintPage event in the .NET Framework SDK. It includes an example. There are also articles you could search for and look at here on CodeProject using the search bar just below the CodeProject logo at the top of the page.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Still trying to wrap my head around this security stuff, I still can't seem to find a simple way to find out if I have the needed permission when running my program before I call the code that would cause the error. What I would like to do is just see if I have access at the begining of my program and if not pop up a message box and exit. I am trying using the Demand but that seems to be the wrong usage, I also tried using the IsUnrestricted() but that doesn't even seem to be true when running locally.
<br />
FileIOPermission canAccess = new FileIOPermission(FileIOPermissionAccess.Write, "C:\\");<br />
try {<br />
canAccess.Demand()<br />
}<br />
catch {<br />
MessageBox.Show "Don't have permissions";<br />
}<br />
Is there another way to go about this?
|
|
|
|
|
You don't need to check, really. An exception will be thrown if you don't have the permission. Also, you can't demand a permission if you don't have it (it's more of a check, really). Such checks are handy when you want to know ahead of time if you can do something or not.
If you need that permission, it must be granted by a code group with an associated permission set (either custom or one of the pre-configured sets, like FullTrust), and the evidence gathered for your assembly must match the membership condition used for that code group (otherwise the code group policy isn't applied and your assembly (/assemblies) aren't granted the permission set you'd expect.
You've got the right idea, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thats what is getting me confused, The .Demand doesn't throw an exception but when I actually try to modify the file then it throws a security exception.
This is some of the test code I have in my program now (that's to test stuff)
<br />
FileIOPermission canAccess = new FileIOPermission(FileIOPermissionAccess.Write, "C:\\");<br />
try {<br />
canAccess.Demand();<br />
File.Delete(cmdArgs[0]);
}<br />
catch {<br />
}<br />
I would expect the .Demand() call to throw the exception but it doesn't, I get the security error when calling File.Delete, which doesn't make sense... (I also tried replacing Write with AllAccess)
The reason I want to run a "pre-check" like this is the delete/renaming stuff doesn't occur until 15 seconds or so in the program so I don't want to make the user wait 15 seconds just to find out that they can't do anything because the code isn't running with the proper permissions.
P.S. The SecurityException message that is thrown is: "Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed."
|
|
|
|
|
That's a good scenario for a "pre-check"!
The problem is that, as the documentation states, Demand checks callers higher in the stack. While all callers higher in the stack may have the permission, you may not. So, lets say you add this code in an event handler you've assigned to an event defined in the BCL assemblies (like handling Button.Click or something). Invoking the delegate (your handler) happens from the BCL. Those assemblies would have FullTrust permissions, but you might not.
Now, when you simply call File.Delete , you become the caller and don't have that permission, so the SecurityException is thrown.
A simple work-around is to attempt to create a dummy file (and delete it, if successful). If you can't write the file, you won't be able to delete a file (well, at least from the CLR's perspective).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I need to run an Expect script (Expect for Windows of course) from managed code. By "run a script" I mean link (dynamically load) the Tcl and Expect libs (DLLs), create a Tcl_Interp and pass it the script to run.
At a high level what does this involve? Can I load (at runtime) the Tcl and Expect DLLs from "unsafe" code? What's the best way to do this?
TIA,
Matt
|
|
|
|
|
Technically, the CLR loads them. What you can do in C# (or in most managed languages) is P/Invoke the native functions, so long as the Tcl libs are resolvable (i.e., in the current process's current working directory - not the DLL's (though that may be the same as the process's current working directory) - or a directory in the PATH environment variable, the same as all executables in Windows).
See the DllImportAttribute documentation in the .NET Framework SDK, as well as Consuming Unmanaged DLL Functions[^].
When you call a P/Invoke method, the CLR loads the native library, gets the proc, pushes your arguments on the stack, and executes the function. The return value is pushed on the stack (typically; depends on calling convention) and returned by the CLR to your managed code.
So, you'll need to read the API documentation for Tcl. Chances are there'll be a setup function (to initialize the execution environment) and a function that will accept arguments (including the path to the Tcl script you want to execute). Getting the path to the Tcl script is easy: let the user specify it on the command line, using an OpenFileDialog , hard-code it (bad idea usually), or whatever.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey does anybody know how to convert an MPEG file to and AVI file??
By BigBlob202
Dinco Inc.
|
|
|
|
|
|
|
Well, he did answer your question.
Converting anything to anything is done using decoders and encoders. Microsoft DirectX does a great job of this and has a managed API for use with .NET. You can find more information about Managed DirectX 9.0b and download the DirectX runtime and managed components from http://msdn.microsoft.com/directx[^].
You chain a decoder for the MPEG (which, keep in mind, there are different codecs for MPEG) to an encoder for an AVI (again, there are many types of encoders and, in fact, AVI does not define a particular codec for either sound (if applicable) or video).
So, to provide you with any examples, it really helps to know exactly what you want to do, because there are so many ways of doing this. Besides, do you really need to write a program to do this? There are tons of free applications on the 'net that already do this, and even the DirectX SDK includes a utility (GraphEdit) that lets you link decoders and encoders (as well as DMOs and other handy utility classes) and do whatever you want (with what's installed on your system).
There are other ways to do this as well, and unless you find a simple unmanaged library that lets you do this with one or two function calls (which you can P/Invoke in C#), they won't be easy to use. .NET is just too high-level to do stuff like this easily (unless you were to write a mixed-mode Managed C++ project that calls native functionality from a managed execution environment which can be used by any other managed language projects, like those in C# and VB.NET).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello, I'm writing a small application in which a draw onto a panel and want to control the painting on the panel with the arrow keys (think of it as a painting program with the keys instead of mouse if you wish..)
Now the thing is, from what I figure the Panel can't gain keyboard focus. So I would need some other way to retrieve the key events. What do I do? Place a dummy control somewher, hide it, give it keyb. focus and then reacts on the events from there?
A better solution? If so please tell me the 'right' way to do it..
/Bjorn
|
|
|
|
|
Is it possible for you to use a UserControl rather than a panel? That would solve your keyboard input problem.
Karl Baum
CEO of KGB Technologies
Specializing in custom software development.
|
|
|
|
|