|
i have a windows service which spans athread whne started
protected override void OnStart(string[] args)
{
Thread mythread= new Thread(new ThreadStart(Run));
mythread.Start();
}
it makes a webrequest(webmethod) in every 10 seconds but sometime i get an exception(only some times) there was not enough thread pool to complete the opertaion why do i get this mesage and what should i do remove this.
thank you
|
|
|
|
|
How to check that I'm connected on the internet with C#.
Help.
Vasildb
|
|
|
|
|
Register the event in the class
System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged += new System.Net.NetworkInformation.NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
and in the event handler check for the Internet availability
void NetworkChange_NetworkAvailabilityChanged(object sender, System.Net.NetworkInformation.NetworkAvailabilityEventArgs e)<br />
{<br />
if (!e.IsAvailable)<br />
{<br />
MessageBox.Show("N/W DISCONNECTED"); <br />
}<br />
}
|
|
|
|
|
This will work, but it is really only going to show if you are connected to the network. This can be different than being connected and able to hit the internet.
You would also need to use a WebRequest or the Ping class and attempt to access a URL that you are reasonably sure will always be available.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
#region Required for internet connection - testing!<br />
[DllImport("wininet.dll", CharSet = CharSet.Auto)]<br />
static extern bool InternetGetConnectedState(ref ConnectionState lpdwFlags, int dwReserved);<br />
<br />
[Flags]<br />
enum ConnectionState : int<br />
{<br />
INTERNET_CONNECTION_MODEM = 0x1,<br />
INTERNET_CONNECTION_LAN = 0x2,<br />
INTERNET_CONNECTION_PROXY = 0x4,<br />
INTERNET_RAS_INSTALLED = 0x10,<br />
INTERNET_CONNECTION_OFFLINE = 0x20,<br />
INTERNET_CONNECTION_CONFIGURED = 0x40<br />
}<br />
#endregion
#region Process - Check internet connection state<br />
private void checkInternetConnection()<br />
{<br />
ConnectionState Description = 0;<br />
<br />
if (InternetGetConnectedState(ref Description, 0))<br />
{<br />
this.tsEmailLabel.Text = "Internet Connection is present.";<br />
this.tsEmailLabel.ForeColor = System.Drawing.Color.YellowGreen;<br />
}<br />
else<br />
{<br />
this.tsEmailLabel.Text = "Internet Connection is not present.";<br />
this.tsEmailLabel.ForeColor = System.Drawing.Color.Crimson;<br />
}<br />
}<br />
<br />
#endregion
Works for me.
Glen Harvy
|
|
|
|
|
Thanks. That works.
Vasildb
|
|
|
|
|
HI,
I must formatting one String like VB6. How I can make?
Es.
Label1 = Format((Num - (Num \ 60000) * 60000) / 1000, "00.000")
Thanks
|
|
|
|
|
// assuming int Num;
double seconds=(Num%60000);
label1.Text=seconds.ToString("00.000");
Luc Pattyn
|
|
|
|
|
The formatting does not work correctly… if I set the number with .ToString(“00,000”) the result is always "nnnnn,000" ("n" is the integer number) … Why?
|
|
|
|
|
Because you are using a comma instead of a period in the formatting string. The period specifies the position of the decimal marker, regardless of what decimal marker is used.
---
Year happy = new Year(2007);
|
|
|
|
|
Thanks ..
|
|
|
|
|
First, let's make the VB6 code better:
Label1 = Format((Num Mod 60000) / 1000, "00.000")
Then we can translate it into C#:
Label1 = ((Num % 60000) / 1000).ToString("00.000")
---
Year happy = new Year(2007);
|
|
|
|
|
The formatting does not work correctly… if I set the number with .ToString(“00,000”) the result is always "nnnnn,000" ("n" is the integer number) … Why?
|
|
|
|
|
Because you are using a comma instead of a period in the formatting string. The period specifies the position of the decimal marker, regardless of what decimal marker is used.
---
Year happy = new Year(2007);
|
|
|
|
|
Thanks a lot ...
|
|
|
|
|
Guffa wrote: Because....
Don't you just hate repeating yourself.
|
|
|
|
|
sw.WriteLine("<body>"); <br />
sw.WriteLine("" + row["columnName1"]); sw.WriteLine("</body>")
The value columnName1 in this case is a static value. how can i make it dynamic? In my case, i have to give variable column names stored in an ArrayList.
sw.WriteLine("" + ArrayList[i]"]);
This gives an error in SQL that ArrayList doesn't match any column name in the database
|
|
|
|
|
Just replace the static string value with whatever you like:
sw.WriteLine("" + row[names[42]]);
Saira Tanwir wrote: sw.WriteLine("" + ArrayList[i]"]);
This gives an error in SQL that ArrayList doesn't match any column name in the database
Hardly. That code doesn't even compile...
---
Year happy = new Year(2007);
|
|
|
|
|
sw.WriteLine("" + row[names[42]]);<br />
I've already tried this. It doesn't work for me. Any other suggetions....??
|
|
|
|
|
No, there aren't any other suggestions, as that is how you do it.
If you want any help with the code that didn't work for you, you have to show it.
---
Year happy = new Year(2007);
|
|
|
|
|
You could iterate through the columns in the same way you do for the rows. Something like this:
sw.WriteLine("<body>");
foreach (DataRow row in myDataTable.Rows)
{
sw.Write("<p>");
foreach (DataColumn column in myDataTable.Columns)
{
sw.Write(row[column.ColumnName]);
sw.Write(" ");
}
sw.WriteLine()
}
sw.WriteLine("</body>");
|
|
|
|
|
Hi all,
I'm trying to track in intermittent exception that occurs in the code of some of my properties. What is the equivalent of
System.Reflection.MethodBase.GetCurrentMethod() for properties? I don't want to hard-code the property name in the catch section because there are a lot of properties in the solution. I'd rather use Reflection.
This is what I'm trying to do:
public bool Exists
{
get
{
try
{
// exception occurs here
}
catch(System.Exception ex)
{
ErrorLogger.Report(System.Reflection.MethodInfo.GetCurrentMethod(), ex); // Logs exception
}
return base.m_Exists;
}
}
Thanks in advance,
Vlad
|
|
|
|
|
use ex.TargetSite.Name property to get the name
public bool Exists<br />
{<br />
get<br />
{<br />
try<br />
{<br />
}<br />
catch(System.Exception ex)<br />
{<br />
ErrorLogger.Report( ex.TargetSite.Name,ex);
}<br />
return base.m_Exists;<br />
}<br />
}
|
|
|
|
|
hi every, one i have project which includes a windwos service and two windows apllication. the windos servcie have two dll files included.it all runs fine and every thing is ok but what i want to while making setup i want the dll files to be incuded in differnt folder and exe(executable) of windows service and windows application in one folder. and the confilg file of windows sevice in cofing folder how can i achle this with setup and deplyoment project of visula studio dot net 2003.
|
|
|
|
|