|
|
<soapbox><blowOffSteam>
I know what I did wrong! I didn't write up a Whitewaper on the the use of System Shutdown functions. The various methods that could be used, and their pro's and con's. Can't forget to cover the security concerns, and OOOh!, AbortSystemShutdown. Need to add a plethora of sameple code too and a couple of complete apps.
Hey! Sounds like an article for CP! I haven't written an article yet, just because of the abuse that comes back when not evey single person who read your article got everything they were looking for, like Cut & Paste source. I'm still debating wheather or not I want to put in the time to do that, then put up with a bunch of n00b's who don't have a clue what they're doing, insisting your code doesn't work. Oh! And if it does work, it doesn't work exactly the way they want it.
</blowOffSteam></soapbox>
I've seen that logo. Man, 30 seconds work in Photoshop, MSPaint would have taken longer... and just because your the only person at the company, it doesn't make you a CEO, but your garanteed to be the mail boy!
But, we keep coming back here doing this day after day because we have this need to want to help people. I'd have to say it's kind of an addiction for me! My girlfriend can attest to that!
Oh well, back in the trenches I go! I've even got a couple of ideas for some articles...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
and just because your the only person at the company, it doesn't make you a CEO, but your garanteed to be the mail boy!
Excellent!
I'm an addict, too, though my contant work schedule drives me away from my computer most times to spend time with my wife*. I just like to help people, and we've both gotten times where people actually take the time to respond and say "thank you". I like that and it shows that there are still decent people left who, while they may not be able to solve their problem themselves (and no one can all the time anyway), they are willing to accept any help and are grateful.
* The guy actually had the nerve to say that posting 1,000 / month is something I shouldn't boast about (which I wasn't, merely pointing out the fact that he and his little buddy are wasting my time - not vice versa - by saying "it doesn't work" and expecting me to debug their code for them) and that's why I spend so many lonely nights. I mean, if you're going to attack someone's character, you should at least check their bio. I think being married would definitely be an indication of not spending lonely nights.
It's good to blow off some steam sometimes, huh? After all the time you I, and a few others put into this forum, pressure and irritation are bound to build-up. I mean, we're only human (at least that's the guise I stick to).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
I mean, we're only human (at least that's the guise I stick to).
I won't tell anyone!
It's good to hear a "Thank You" now and then. It helps us to keep coming back for more!
Anyway... Thanks Heath! Keep posting the GREAT work! I'm learning something new from you every day!
I've gotta get out of here, go wine and dine the little woman, and get in some cuddle time! See y'all tomorrow!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
Is there any way (API,...) to use Raster or Bitmap fonts in C# ?
In the Documents there's a note that there's no support for those type of fonts in .NET
Could anyone please give a hint or workaround for this
Thanks in advance,
nbj
|
|
|
|
|
Hi,
If you have a bitmap containing a bitmap font you can load that bitmap and when you want to write the letter 'a' you would draw that portion of the bitmap that has the 'a' on it. The portion draw is called a frame. Your bitmap would consist of a frame for each of the 26 letters and whatever punctuation you desire.
In the article "Invasion - A computer game using DirectDraw" By Mauricio Ritter found at http://www.codeproject.com/directx/invasion.asp. This approach is taken.
He does this using DirectDraw, but the same approach can be taken with GDI+.
You can implement your own raster font as well, but that would be much more work.
Karl Baum
CEO of KGB Technologies
Specializing in custom software development.
|
|
|
|
|
Hello,
I am trying to export a large set of data in to csv format. I do all the coding in C# to get the data in CSV format. I use Response.write and write the CSV data to the client in chunks. When I first flush the data buffered the IE asks the client to open/save the file.
When I make the choice to open the file it opens it in Excel and then I save it when everything is done using file->save as... option. The file thus saved is smaller in size when compared to the file saved using the saving option on the IE dialog. Why is this?
I would really appreciate any inputs on this.
Thank you
NSK
|
|
|
|
|
How big is the difference? A couple of bytes or twice as much?
If you save the .CSV file as a Unicode encoded text file and then Excel resaves it as an ASCII, UTF-8, or some other 8-bit encoding, then the filesize will be cut in half.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks guys for the reply. The size going in to half is a very good point Dave. But the .CSV file on clicking save comes to 1.67MB and the one opened with excel and then saved comes to 1.16MB. The difference is few bytes. I donot specify any format for saving and windows takes is default and which I think is ASCII.
Heath's statement about binary format compression that Excel does makes some sense.
With the input above can you guys please explain this problem.
Thank you
NanSK
|
|
|
|
|
In addition to what Dave said (and to note, ASCII itself is actually a 7-bit encoding), Excels default save file filter is the Excel spreadsheet format (the .xls extension). This binary format with some compression will be smaller as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks guys for the reply. The size going in to half is a very good point Dave. But the .CSV file on clicking save comes to 1.67MB and the one opened with excel and then saved comes to 1.16MB. The difference is few bytes. I donot specify any format for saving and windows takes is default and which I think is ASCII.
Heath's statement about binary format compression that Excel does makes some sense.
With the input above can you guys please explain this problem.
Thank you
NanSK
|
|
|
|
|
I already did explain the problem. Even though Excel may be the default viewer for opening CSV (actually, the MIME type you're using), when a user saves it will default to saving as an Excel Spreadsheet - a binary format. What don't you understand about that? After they save the file, if the extension is .xls, it's most likely an Excel Spreadsheet.
Besides, what difference does it make? It's smaller in size and, if it contains all the data, there's nothing wrong.
Even if the file is saved as a CSV by Excel (it can, but users typically have to change the file filter), it may optimize the fields in the CSV more than you've done. For example, quotes are only needed when a field contains a comma in its code. If you quote everything, Excel will most likely strip-out the superfluous quotes and, most likely, will save as the original encoding unless the user changes it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
My understanding of the way exception work in .NET is that once an exception is thrown, the run-time unwinds the call stack until either
(a) the call stack is empty (game over) or...
(b) a catch block is found that "handles" the thrown exception
I tested this my understanding of this with the program below.
And just as I thought it would, after level5() through the exception the Runtime unwound the call stack back to level1().
My understanding is that the objectless "catch" will catch -ALL- exceptions. Period. Even unmanaged exception one of my books says.
So... if I define my static Main() as:
static void Main()
{
try
{
Application.Run(new Form1());
}
catch
{
MessageBox.Show("Not so fast!");
}
}
... is it possible for an (some) execptions to "leak" out to the Runtime?
Thanks,
Cunfewsdish
===============================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Exceptional.cs
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
level1();
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void level1()
{
try
{
level2();
}
catch
{
MessageBox.Show("Kawt!", "Level 1");
}
}
private void level2()
{
try
{
level3();
}
catch(System.ApplicationException se)
{
MessageBox.Show("Caught!", "Level 2");
}
}
private void level3()
{
level4();
}
private void level4()
{
level5();
}
private void level5()
{
throw new System.Exception("Error!");
}
}
}
|
|
|
|
|
If there is an Exception in the Runtime itself, it may crash your app, but an exception from inside your app can't leak out to the Runtime if you have an expcetion handler in place to grab it.
There is an exception though. Not all exceptions will propogate up the call stack. The .NET Framework wraps and applications message pump in an exception handler. If an exception is generated that the application code doesn't handle, the exception handler around the message pump will handle it. For an example, you have two forms, one is your main form and the other is a dialog form. This means an exception generated in the dialog form will NOT propogate up to the main form that Show()'d it. Understand?
If not, check this[^] article on MSDN for a quick example demonstrating this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks Dave. I was not aware that .NET wrapped each msg pump with an exception handler although that makes good sense. Is it possible to instruct (using your example of 2 forms, main and dialog) the dialog's wrapped exceptional handler to "hand off" caught exceptions back to the main form's code?
TIA,
Matt
|
|
|
|
|
No, it's not. The message pump handler can't be bypassed, unfortunately, and it's behavior is to put up the usual message box you see for an "unhandled" exception.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Im am in the process of creating a small util app for my development. I am developing using NAnt and NUnit. I was tired of clicking on *.bat files to build the program every time (I have 8 different bat files for different purposes) so I wanted to create an application where I could set the parameters in a GUI and then build the program with a click of a button.
So the question is, how do I start one application from another? In this case I have a .NET windows forms application and want to start NAnt from it with a set of arguments?
|
|
|
|
|
Quite simply: see the System.Diagnostics.Process class:
Process.Start("build.bat", "/some command /line arguments"); You can do more like redirect stdout, stderr, and stdin and perform a ShellExecuteEx on file types as well. See the class library documentation for the Process class in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks. That was exactly what I wanted. But I do have one problem. I cannot make the commandline arguments work correctly. I wanted to redirect the std out to a textbox I have. This is the code (basically copied from .Net documentation):
<br />
Process myProcess = new Process();<br />
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("nant", "-D:debug=" + debug + " -D:doc=" + doc + " -buildfile:serverbuild.build -defaultframework:net-1.1");<br />
myProcessStartInfo.UseShellExecute = false;<br />
myProcessStartInfo.RedirectStandardOutput = true;<br />
myProcess.StartInfo = myProcessStartInfo;<br />
<br />
StreamReader myStreamReader = myProcess.StandardOutput;<br />
string myString = myStreamReader.ReadLine();<br />
this.output.TB.Text += myString;<br />
myProcess.Close();
This code starts nant like it should and redirects the output to my textbox but it completely ignores the arguments. Any ideas what might be causing that?
|
|
|
|
|
It won't ignore those arguments, but your arguments may be incorrect. Take, for example, "-D:doc=" + doc + "..." . If doc has any spaces it in, this will cause an error but you should see that in your output. This will cause nant to either exit in error or run with the doc symbol defined as the first word before a space in the doc variable.
I also noticed you're not calling Process.Start , though maybe an oversight when you pseudo-copied example code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes. I have the start in the code I tested. The complete code looks like this:
Process myProcess = new Process();<br />
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("nant", "-D:debug=" + debug + " -D:doc=" + doc + " -buildfile:serverbuild.build -defaultframework:net-1.1");<br />
myProcessStartInfo.UseShellExecute = false;<br />
myProcessStartInfo.RedirectStandardOutput = true;<br />
myProcess.StartInfo = myProcessStartInfo;<br />
myProcess.Start();<br />
<br />
StreamReader myStreamReader = myProcess.StandardOutput;<br />
string myString = myStreamReader.ReadLine();<br />
this.output.TB.Text += myString;<br />
myProcess.Close();
When I ask the ProcessStartInfo to show me what the argument string looks like it prints this:
-D:debug=true -D:doc=false -buildfile:serverbuild.build -defaultframework:net-1.1
In the *.bat file I used before to build the application the complete line to build the application was this:
nant.exe -D:debug=true -D:doc=false -buildfile:serverbuild.build -defaultframework:net-1.1
So the argument string looks correct.
|
|
|
|
|
Then make sure you set the current working directory to the directory that has the .build file (or use the fully-qualified path). The current working directory is either the executing application's directory, or the directory you're in when you launch the application from the command-line. You can do this by setting the ProcessStartInfo.WorkingDirectory to the correct directory.
If this doesn't help, please include what the standard output reads after the process exits. Without details about the problem, it's difficult to help you; all I can do is offer suggestions without knowing more.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you really much for trying to help me
I now noticed that the build process actually works. NAnt builds the application correctly, but it is the output that confuses me. I have redirected the output to a textbox. The textbox contains this after the application is run:
NAnt 0.84 (Build 0.84.1455.0; net-1.0.win32; release; 2003-12-26)
And thats all. So it works some way but not completely. For example it says "net-1.0" but I use 1.1, but the build works and builds with 1.1.
|
|
|
|
|
Obviously that's the version information for NAnt itself: Build 0.84.1455.0, built on .NET 1.0 in release mode on December 26th, 2003.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
But the output from the buildprocess doesnt work. Obviously it works to a certain extent since it shows that NAnt started but nothing more. Do you have any idea why that is?
|
|
|
|
|