|
Hello everyone,
When we call Environment.Exit to terminates a console application or a Windows service,
1.
All the expected finally blocks are ensured to be executed, so resource leak?
2.
No exception occured (i.e. when invoking Environment.Exit, no exception thrown, like invoking Thread.Abort will throw ThreadAbortException?)
thanks in advance,
George
|
|
|
|
|
George_George wrote: All the expected finally blocks are ensured to be executed, so resource leak?
No, managed threads will be suspended and then terminated, so the CLR does not make any explicit attempt to execute finally blocks. It does execute finalizers though. And your process is going down, so the OS is going to cleanup all process local resources anyway.
George_George wrote: No exception occured (i.e. when invoking Environment.Exit, no exception thrown, like invoking Thread.Abort will throw ThreadAbortException?)
No again - it doesn't throw any exception as part of normal execution.
|
|
|
|
|
Cool, Senthil!
Question answered.
regards,
George
|
|
|
|
|
Please help!!
Can any one tell me how to extract Excel worksheet images and store them in database?
Thanks in advance.
|
|
|
|
|
Did you even try searching codeproject before asking this?
[^]
Loading an excel spreadsheet is trivial, as is putting the data into a database.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: Did you even try searching codeproject before asking this?
Did you read my question carefully before you reply?!!
I'm trying to read All images in an Excel file (not the spread sheet data)
and store these images in database.
Please don't reply if you have no idea.
|
|
|
|
|
Hi C# guyes,
hope, that somebody can help me. I tryed for some days now, to get my code working. But without luck. I can get the temp of my CPU out in a messagebox, but when i am trying to covert it to celcius from kalvin i get no results. I want the temp. in celcius out in a messagebox. How do i do that? Can somebody explain me how to? I will pass my code, thanks a lot
kennet
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace GetCpuTemp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ManagementClass processClass = new ManagementClass (@"root\WMI:MSAcpi_ThermalZoneTemperature");
foreach (ManagementObject service in processClass.GetInstances())
{
MessageBox.Show("CPU Temperature: " + service.GetPropertyValue("CurrentTemperature"));
}
}
static decimal ConvertToCelsius(string reading)
{
return (decimal.Parse(reading) / 10 - 273.15m);
}
}
}
modified on Sunday, April 27, 2008 7:52 AM
|
|
|
|
|
I though 1 Kelvin == 1 Celsius? Whats the /10 for?
You should also check what decimal.Parse actually returns, to make sure that parts working correctly.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
(0 K = -273.15 °C and 273.16 K = 0.01 °C).[^]
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Thomas Stockwell wrote: (0 K = -273.15 °C and 273.16 K = 0.01 °C).[^]
Yeah, so 1K = 1°C
Relative, not absolute.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Hi Thomas,
Thanks for your help,but I dont really understand it. I am just a beginner.
This code works properbly
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace GetCpuTemp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ManagementClass processClass = new ManagementClass(@"root\WMI:MSAcpi_ThermalZoneTemperature");
foreach (ManagementObject service in processClass.GetInstances())
{
MessageBox.Show("CPU Temperature: " + service.GetPropertyValue("CurrentTemperature"));
}
}
The messagebox show me a temp. of 3012 kelvin and my problem now is, that I like to convert it to celcius and read it out on a messagebox. Can you please help me, because I dont know how to do it. I tryed this code, but I dont know how to get it out in a massegebox.
static decimal ConvertToCelsius(string reading)
{
return (decimal.Parse(reading) / 10 - 273.15m);
}
Regards Kennet
|
|
|
|
|
kennet1974 wrote: I tryed this code, but I dont know how to get it out in a massegebox.
Really ? In that case, you are definately very much a beginner. You should buy a very basic C# book and work through it, instead of relying on these forums, you're not really ready to make this your main source of information.
Never call decimal.Parse, use TryParse so your code never blows up.
Two clues:
1 - every object in C# has a tostring method
2 - if you concatenate anything to a string, C# calls that for you, for free.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
All,
I have a requirement to find out where a particular process was started from (c:\somepath for example).
The system.diagnostics namespace doesnt appear to have this info, does anyone have any ideas?
Thanks,
|
|
|
|
|
It does have the info, but its a little hidden. What you need to look at is Process.MainModule.FileName .
So this would show you the paths for all the currently running processes:
foreach(Process proc in Process.GetProcesses())
{
MessageBox.Show(proc.MainModule.FileName);
}
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
|
Hello everyone,
I am new to this API. After some study, Application.Exit should only be used in Forms application, and in console/Windows service application without any GUI Window, we should not use it to exit application, right?
thanks in advance,
George
|
|
|
|
|
|
Cool, Urs!
I think the answer is, in console and Windows service application, Aplication.Exit has no use and it is not used to cause process to terminate, right?
regards,
George
|
|
|
|
|
Application.Exit will never terminate the process.
Normally you have something like this in your winforms app:
public void Main()
{
MyForm form = new MyForm();
Application.Run(form);
}
Application.Exit will cause that the Application.Run method returns to the Main method and then, of course, the process will end, because nothing is done afterwards.
best regards
Urs
-^-^-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Thanks Urs,
So, for console application and Windows service application without GUI, Application.Exit is useless, right?
regards,
George
|
|
|
|
|
If there is no Application.Run process running, then the Application.Exit function is useless.
As far as i'm aware your statement is true.
Cheers,
|
|
|
|
|
Cool, Mark!
Question answered.
regards,
George
|
|
|
|
|
Hi George,
A lot of applications don't need Application.Exit(), even Windows Forms applications
can do without if one wants them to only terminate when the main form gets closed.
Service means no forms, means no Application.Exit().
I trust you are aware of Environment.Exit()?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Yes, Luc! Currently, I am using Environment.Exit (-1). And I want to keep on learning new things. Is Environment.Exit safe that no resource leak will occur (and all expected exception handler and finally blocks are executed)?
regards,
George
|
|
|
|
|
Hi George,
1.
yes Environment.Exit() will clean up and avoid leaks.
Everything that terminates a process will clean up the resources allocated by
the process itself, that is basic functionality in Windows itself.
Nevertheless, it is good practice to do it explicitly;
and you should clean up if your program has two or more parts that are rather
independent, so after part 1 you could and should clean up before starting
part 2, so part 2 gets a maximum of available resources (memory, handles, whatever)
and hence gets the best performance.
2.
George_George wrote: finally blocks are executed)?
Why don't you try it? you really should replace some of your questions by
looking it up yourself and/or testing it yourself. Here is enough code to
figure it out (put it in e.g. a button click handler):
try {
Application.Exit();
} finally {
StreamWriter tw=File.CreateText("finally.txt");
tw.Close();
}
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|