|
Can you post the code snippet?
|
|
|
|
|
This is the main function:
public void Form1_Main()
{
if (copyBool)
{
//Find if Application is running
copyBool = false;
// int window = FindWindow("Virtual DJ", true);
// if(window == 0)
// this.Close();
int window = 1;
if (window != 0)
{
string FolderPath = null;
TreeNode tr = null;
Diractory_Path dp = new Diractory_Path();
dp.GetFolderMusicPath();
FolderPath = dp.GetPathString();
if (FolderPath == "")
{
MessageBox.Show("The Path is empty, the program ended!!!");
this.Close();
}
label1.Text = "The Files are being transfared!!!";
///This is The copy files function!!!
CopyFolderData(FolderPath, ref tr);
///This is the Uodate XML section.
label1.Text = "The XML are being Updated!!!";
XML_Handle xml_h = new XML_Handle();
xml_h.XMLHandleMain();
if (xml_h.GetXMLFile() == " ")
this.Close();
xml_h.HandleXMLData();
///This is the Playlists creation.
label1.Text = "The PlayLists are being created!!!";
PlayList playList = new PlayList();
playList.PlayListHandleMain(tr);
label1.Text = "Test Was Finished!!!";
System.Threading.Thread.Sleep(2000);
this.Close();
}
}
}
This is the call:
static void Main()
{
Application.Run(new Form1());
this.Form1_Main();
///The installation project starts here!!!
}
|
|
|
|
|
Hello everyone,
I am using C# and Visual Studio 2005 to develop a class library. I am wondering whether there are any built-in log component in C# so that I can utilize directly other than write from scratch?
I am also wondering if there does exist such log component, if multiple processes using the built-in log component to open the same log file to write log (in my application, I want all processes which loads the class library DLL to have a common log file), will there be any risk of racing condition (e.g. interlacing log of one process and another process)? Do we need any lock/synchronization approach?
thanks in advance,
George
|
|
|
|
|
George_George wrote: I am wondering whether there are any built-in log component in C# so that I can utilize directly other than write from scratch?
There are classes that allow you to write to the event log. However, if you want a proper log component you'll have to look for things like log4net or the Microsoft Enterprise Library Logging Application Block.
|
|
|
|
|
Seconded on log4net. Very easy to get up and running.... or logging.
|
|
|
|
|
Thanks Mark,
Microsoft has no built-in Log function?
regards,
George
|
|
|
|
|
Well we went with log4net because it had some features we wanted to use in the future. Firstly we had it logging to SQL server, but then we got it to shoot out UDP packets for high priority log entries to a remote console (in another country)!
You can log to the windows event log using (it think) classes in System.Diagnostics, thats quite easy to get working.
|
|
|
|
|
Thanks Mark,
What means *shoot out UDP packets for high priority log entries*? Why using UDP for high priority? What packages do you use for normal priority log -- TCP?
regards,
George
|
|
|
|
|
Ah sorry to be confusing. We log everything to SQL server. High priority messages (non sensitive) get stuffed in a UDP packet (theres a UDP log appender for log4net) and sent to my laptop. I run a program on my laptop that pops up - so if anything serious is going on then I know about it.
As for UDP/TCP... UDP is a little more convenient than TCP, as there is no connection setup. You can just stick a packet with a destination address out on the wire and it will (probably) get to the destination
|
|
|
|
|
Hi Mark,
You mean UDP transmission is faster then TCP, right?
regards,
George
|
|
|
|
|
Thanks Colin,
You mean Microsoft .Net has no built-in log function? What is *Microsoft Enterprise Library Logging Application Block*? Is it easy to use? I only want to write to local file, no complex function needed.
regards,
George
|
|
|
|
|
Here's[^] a simple-minded logger that may meet your initial needs.
/ravi
|
|
|
|
|
Thanks Ravi,
Seems it does not provide function to limit the size of log?
regards,
George
|
|
|
|
|
From the help file of ConnectionState enum type:
Broken The connection to the data source is broken. This can occur only after the connection has been opened. A connection in this state may be closed and then re-opened. (This value is reserved for future versions of the product.) <br />
Closed The connection is closed. <br />
Connecting The connection object is connecting to the data source. (This value is reserved for future versions of the product.) <br />
Executing The connection object is executing a command. (This value is reserved for future versions of the product.) <br />
Fetching The connection object is retrieving data. (This value is reserved for future versions of the product.) <br />
Open The connection is open.
I'm using .NET 2.0. Does this mean that the values "Broken", "Connecting", "Executing" and "Fetching" are useless?
Does .NET 3.0 or 3.5 changed this?
Thanks.
|
|
|
|
|
in a text box which accepts only numbers ,when the user tries to input a alphabatical character ,i want to ignore the key stroke ?
|
|
|
|
|
Why not use a MaskedTextBox?
|
|
|
|
|
You can set up an event handler for keypress event to check whether the key that was pressed is digit or not. Depending on that you can ignore the key if it isn't a digit or a backspace
|
|
|
|
|
Hi
I want to transmit a live video from server to multi clients using UDP, I m working in C# and I've captured the video from WebCam. So please tell me the steps to be follow to accomplish this task.OR if u have any tutorials or links related to my task plz Notify me.
Regards.
Shanzay
|
|
|
|
|
i have text column in the database(access).the column contains a image path information.all i have to do is to show the image in crystal reports .if i use the ole object then it is coming fine in the crystal reports but i am stuck at showing the pic when showing the image in the crystal reports while accessing the path from the database.
Soniagupta1@yahoo.co.in
|
|
|
|
|
Sonia Gupta wrote: he column contains a image path information.all i have to do is to show the image in crystal reports
Showing dynamic images in crystal reports would be a hectic problem. Passing image name and showing it over there is not possible. One option would be storing image in database as BLOB. Crystal reports having capability to render this BLOB data. But for this you need to switch your DB to SQL Server.
|
|
|
|
|
how can i retrieve the images from the database to my form in c#? the images are in the ole type column
Soniagupta1@yahoo.co.in
|
|
|
|
|
My application will generate a word document as report. The application created Word Application and Document objects.
When users click on Close or the "X" icon on the up right corner. The application will intercept word DocumentBeforeCloseEvent, to ask users Save, No or Cancel to the document changes. Everything works fine except when users click on "Cancel", Word still displays it's own Dialog for users to select Yes, No or Cancel for saving the document changes.
Is there anyway to prevent this Word dialog because my application already process uses decision?
Here is part of the code:
Word_DocumentBeforeClose is used to process users decision.
The last part of If in else is to process when Cancel is clicked.
namespace HandleWordEvnts
{
public partial class Form1 : Form
{
#region properties
Word.ApplicationClass wordApp;
Word.Document wordDoc;
string docName;
#endregion properties
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//===== Create a new document in Word ==============
// Create an instance of Word and make it visible.
wordApp = new Word.ApplicationClass();
wordApp.Visible = true;
// Local declarations.
Object oMissing = System.Reflection.Missing.Value;
// Add a new document.
wordDoc = wordApp.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing); // Clean document
// Add text to the new document.
wordDoc.Content.Text = "Handle Events for Microsoft Word Using C#.";
docName = wordDoc.Name;
//============ Set up the event handlers ===============
wordApp.DocumentBeforeClose +=
new Word.ApplicationEvents2_DocumentBeforeCloseEventHandler(
Word_DocumentBeforeClose);
}
// The event handlers.
private DialogResult showSaveFileDlg(ref string fileName, ref string filePath)
{
DialogResult dlgRes = DialogResult.None;
object locker = new object();
Thread.Sleep(1000); //time needed for dialog to display
lock (locker)
{
saveFileDialog1.Title = "App Save As";
saveFileDialog1.FileName = filePath != "" ? (filePath + "\\" + fileName) : fileName; //init full name
saveFileDialog1.InitialDirectory = filePath;
saveFileDialog1.Filter = "Word Document (*.doc)|*.doc| Plain Text (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
dlgRes = saveFileDialog1.ShowDialog();
if (dlgRes == DialogResult.Cancel) return dlgRes;
fileName = saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.LastIndexOf("\\") + 1);
filePath = saveFileDialog1.FileName.Substring(0, saveFileDialog1.FileName.LastIndexOf("\\"));
return dlgRes;
}
}
private void Word_DocumentBeforeClose(Word.Document doc, ref bool Cancel)
{
docName = doc.Name;
string fileName = doc.Name;
string filePath = doc.Path;
// ask user to save or not
DialogResult dlgRes = DialogResult.None;
AskSaveCnanges askSave = new AskSaveCnanges();
askSave.setTxtBox1 = filePath != "" ? (filePath + "\\" + fileName) : fileName;
askSave.setTxtBox1Readonly = true;
askSave.ShowDialog();
if (askSave.DlgRes == DialogResult.Yes) //user agrees to save
{
Thread showWordDlg = new Thread(delegate() { dlgRes = showSaveFileDlg(ref fileName, ref filePath); });
showWordDlg.SetApartmentState(ApartmentState.STA);
showWordDlg.Name = "DocClose";
showWordDlg.Start();
showWordDlg.Join();
if (dlgRes == DialogResult.OK) //user agrees to save
{
MessageBox.Show("DocumentBeforeClose ( Saved " + doc.Name + " )","APP");
//Save the file, use default values except for filename
object ofileName = filePath + "\\" + fileName;
object optional = Missing.Value;
try
{
doc.SaveAs(ref ofileName, ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional, ref optional);
//doc.Save();
doc.Saved = true;
object saveChanges = true;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
wordApp.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
}
catch (COMException e)
{
MessageBox.Show(e.Message,"ApP.DocumentBeforeClose");
}
//saveAs = false;
//Cancel = true;
}
}
else if (askSave.DlgRes == DialogResult.No)
{
MessageBox.Show("DocumentBeforeClose ( Not Saved " + doc.Name + " )","APP");
Cancel = true;
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
wordApp.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
}
else
{
MessageBox.Show("DocumentBeforeClose ( Canceled " + doc.Name + " )","APP");
//When users cilck on Cancel button.
// Cancel is set to true but Word still displays it's own dialog.
Cancel = true;
doc.Saved = false;
wordApp.Activate();
Thread.Sleep(5000);
//send key does not work either
SendKeys.SendWait("{RIGHT}{RIGHT}{ENTER}");
}
}
}
|
|
|
|
|
Hey,
I'm having some problems starting a command-line program using Process.Start(). I pass it the filename and arguments, and it runs the program, but instantly crashes and a "Program has stopped working" error comes up. I can't figure out what is wrong. The program runs fine from the command line and when I use a shortcut, and Process.Start() runs other programs fine. Can anyone tell me what is wrong?
For reference, I am running this in Vista.
|
|
|
|
|
As per my experience you have problem in passing arguments.
Try without argument passing, and change the way to pass arguments.
Hope you will find solution.
I have tried to give hint to your problem.
Best Regards,
Chetan Patel
|
|
|
|
|
Well classical problems like this are solved by using unmanaged code equivilant to the System.Diagnostics namespace from the win32 api.
(Hint: search MSDN)
Hope this helps!!;)
To follow the path, Walk with the MASTER, See through the MASTER, Be the MASTER!
|
|
|
|