|
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?
|
|
|
|
|
Never mind. I figured it out. I switched the ReadLine() to a ReadToEnd().
|
|
|
|
|
Hello,
I cant seem to debug an SQL stored procedure using VS .Net's debugger.
I set breakpoints on the data adapters call to Fill and the stored procedures first line.
However, when I debug, the breakpoint in the stored procedure turns to a question mark and says "The breakpoint will not currently be hit. Unable to bind SQL breakpoint at this time. Object containing the breakpoint not loaded".
What am I doing wrong? I want to break on the Fill call, and then step into it.
Thanx for the help,
-Flack
|
|
|
|
|
On what line did you set your breakpoint? The Create Procedure? Make sure you put it on the the first line of code inside the procedure. Or better yet, test your SQL in the SQL Queary analyzer first and you won't have to set that kind of a breakpoint. Also, in your Project Properties, under Debugging (I Think!), make sure that you have SQL debugging enabled.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The problem description goes like this...
person A is accessing a record to update, i want this record to be locked till the person A finishes his updation.
i want this to be implemented at BLL(Not IN database)
Regards,
|
|
|
|
|
The database is the best place to do it? Why would you want to do it anywhere else. You do understand that, unless you're using XML Web Services, .NET Remoting, or some other singleton that handles all user requests, there's no better way to do it and that every process has distinct resources?
In SQL Server, for example, you can use row-level locking while updating data like so:
UPDATE MyTable WITH ROWLOCK
SET SomeField = 'Some Value'
WHERE ID = 1 Without a daemon brokering calls to clients (which an RDBMS already is, so why write another?), there's no way to lock an object (row, table, etc.) for one particular user from others.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You would pretty much need to use the database to do this. You could put a boolean column on your table that would indicate the row is locked. And you may want to make use of a timestamp column as well to ensure that when you update the row, that you know that you read the most current record before attempting that update.
|
|
|
|
|
I assume you mean that the person A has a record on his screen, and you want to lock it until he is done editing it. (If thats not what you mean, then check the preceeding comments for your answer).
That is known as "pessimistic concurrency", which is out of fashion, for good reason. The most common technique nowadays is "optimistic", whereby you assume that no-one else will change the record, but trigger an error if someone has. This is usually achieved through the use of timestamps on the records.
my blog
|
|
|
|