|
Hello all,
I would like to know what the best practice is for testing if a program has a valid internet connection. I have a function which tells me if the program is connected or not but I would hate to have to call this everytime I need to perform some operation.
What I am looking for is something like in Messenger when you lose an internet connection it notifies you. Am I limited to a timer that constantly checks for the internet connection or is there some way my app can receive a message when a connection gets unplugged or something similar.
Does this make any sense? Any help is greatly appreciated.
Thanks,
Troy G
|
|
|
|
|
Yes, you have to check it in a timer or thread. Whats the problem with that?
Mazy
You're face to face,
With the man who sold the world - David Bowie
|
|
|
|
|
Mazy,
No problem. Just thought there may be something else I could do that would be easier on resources.
Thanks for responding,
Troy
|
|
|
|
|
Hi there
I have the same problem as yours
but u have at least made a function to get yr work done.
I couldnt even do that !
can u plz pass a copy of that function to me?
Thanks
VisionTec
|
|
|
|
|
visiontec wrote:
can u plz pass a copy of that function to me?
Just P/Invoke InternetGetConnectedState[^] and call it when your Tick event fires from your timer.
- Nick Parker My Blog
|
|
|
|
|
This is what I use, there are a bunch of them...
//Creating the extern function...
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
//Creating a function that uses the API function...
public static bool IsConnectedToInternet()
{
int Desc ;
return InternetGetConnectedState(out Desc, 0);
}
|
|
|
|
|
im using ADO.Net to connect to my database(im using Visual Studio .NET 2003) whenever i add the namespace System.Data now when i add this
i dont have System.Data.OleDb in the list when intelisense pops up...is something wrong?...so im using System.Data.SqlClient...can this work with SQL SERVER 7.0 databases...i read in a book(C# How To Program by Deitel & Deitel) that System.Data.SqlClient only for SQL SERVER 2000 databases
oh yeah can i know any WEB SITE where i can get a really good explaination abt Manipulating a Database.(ADDING,INSERTING,DELETING,MODIFYING...ETC)
Arvinder Gill
|
|
|
|
|
ASGill wrote:
so im using System.Data.SqlClient...can this work with SQL SERVER 7.0 databases
Yes, it works with SQLServer 7 and later.
ASGill wrote:
i read in a book(C# How To Program by Deitel & Deitel) that System.Data.SqlClient only for SQL SERVER 2000 databases
Nope.
ASGill wrote:
i dont have System.Data.OleDb in the list when intelisense pops up...is something wrong
Go to project references and add System.Data namespace.
Mazy
You're face to face,
With the man who sold the world - David Bowie
|
|
|
|
|
hi!
what should i do when i make use of the ReadFile function from the Packet Analyzer program(by floack), and i get an error saying that "a device attached to the system is not functioning". I am trying to integrate a ping feature to that program when i would send a ping request and wait for its reply. i am able to sucessfully send the request, however when i use the ReadFile to listen to the same port, i get the error stated above. can anyone help me with this problem?
Thanks!
Lots
|
|
|
|
|
This isn't a forum for specific application issues like that. If you have a quesiton about that program or wish to report a bug, please contact the author or visit any forums that application may have attached.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi!
what should i do when i make use of the ReadFile function from the Packet Analyzer program(by floack), and i get an error saying that "a device attached to the system is not functioning". I am trying to integrate a ping feature to that program when i would send a ping request and wait for its reply. i am able to sucessfully send the request, however when i use the ReadFile to listen to the same port, i get the error stated above. can anyone help me with this problem?
Thanks!
Lots
|
|
|
|
|
Hi, I'm working on a small app that has a tab panel and I need to create a new tab with a few buttons and text boxes each time a text file is opened. My problem is how to create an identical tab each time with all of the same buttons and boxes with all the same code. Any ideas? Thanks.
-NF
|
|
|
|
|
The best way is to extend TabPage with your own class and add all your controls and default logic to that class. Whenever you need to add a new tab to your TabControl , simply instantiate a new instance of your custom TabPage class and add that to TabControl.TabPages .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok thanks for the help, I did what you instructed but the new TabPage will not show up on the form. I looked around for methods that seemed to help update Windows Forms controls. I found SuspendLayout() and ResumeLayout() and also Refresh(). I invoke SuspendLayout on the From, TabControl, and the TabPage before adding the controls to the TabPage, then to the TabControl. Then I do ResumeLayout(false) for all three objects after everything is done. That didn't work so I called Refresh() on everything that I logically could. Still no new tab? I made sure I added the TabPage to the TabControl and everything. Any ideas? Thanks again for your help.
-NF
|
|
|
|
|
Never mind I just had to much code mixed up all over the place, anyway, it works now. Thanks again for your help.
-Noah Fields
|
|
|
|
|
How do I make an input box in C#? Also, how do I make the null value of the text of a label control a condition for an if statement?
|
|
|
|
|
Eric Houser wrote:
how do I make the null value of the text of a label control a condition for an if statement?
if(label1.Text=="")
{...}
Eric Houser wrote:
How do I make an input box in C#?
TextBox Control.
Mazy
You're face to face,
With the man who sold the world - David Bowie
|
|
|
|
|
Actually, null and an empty string are two different things entirely. To check for null (to the original poster), simply use obj == null , where obj is an reference variable (value types cannot be null).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yah, null and emtpy are different but I think he meant that How can I check there is no string in label.
Mazy
You're face to face,
With the man who sold the world - David Bowie
|
|
|
|
|
Hi to all,
I have 3 dialogs which are Parent, Dialog and Child. When I press My Parent dialog's menu I come across with my dialog box. Everything ok for now. But when I press the button on dialog I want my child dialog inside the parent dlg box. I think I made something wrong the code runs without any errors but doesn't make what I want??? Might be a logic failure in somewhere. This trashed all my day (I brainstrom and checked lots of articles about forms...) But couldn't get a result. So any help would be greatly appreciated. I am posting all my 3 file(Sorry for the pollution)
Thank you,
Cem Louis
/////////////
//Parent.cs//
/////////////
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Test1
{
/// <summary>
/// Summary description for Parent.
/// </summary>
public class Parent : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Parent()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "Show Dialog";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Show!";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// Parent
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "Parent";
this.Text = "Parent";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Parent());
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Test1.Dialog Dialog = new Test1.Dialog();
Dialog.Show();
}
}
}
/////////////
//Dialog.cs//
/////////////
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Test1
{
/// <summary>
/// Summary description for Dialog.
/// </summary>
public class Dialog : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Dialog()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 104);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Show Child";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Dialog
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Name = "Dialog";
this.Text = "Dialog";
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
Test1.Child chform = new Test1.Child();
Test1.Parent Parent = new Test1.Parent();
chform.MdiParent = Parent;
chform.Show();
}
}
}
////////////
//Child.cs//
////////////
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Test1
{
/// <summary>
/// Summary description for Child.
/// </summary>
public class Child : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Child()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Child";
}
#endregion
}
}
|
|
|
|
|
Hi,
I think I know the problem.
When you launch the program, you create an instance of the class "parent". But since you do not pass the object to Dialog, you can't refer to it there.
Here's what I did that seemed to produce the effect you want:
1) modify Dialog.cs so that you can store the parent object somewhere. Add this on line 20 or so
<br />
public class Dialog : System.Windows.Forms.Form<br />
<br />
{<br />
private Form MainForm;
<br />
private System.Windows.Forms.Button button1;<br />
2) Modify the constructor for for Dialog so you can pass it a the parent.
<br />
public Dialog(Form frmMain)
{<br />
InitializeComponent();<br />
<br />
this.MainForm = frmMain;
}<br />
<br />
3) Pass the parent object when you instantiate the form...in Parent.cs
<br />
private void menuItem2_Click(object sender, System.EventArgs e)<br />
{<br />
Test1.Dialog Dialog = new Test1.Dialog(this);
Dialog.Show();<br />
}<br />
4) Then (finally!) set the mdiparent for the Child
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
Test1.Child chform = new Test1.Child();<br />
chform.MdiParent = this.MainForm;<br />
chform.Show ();<br />
}<br />
Hope this helps! I can send you the source code if this post doesn't get the message across...
Bill
|
|
|
|
|
//bill dean says kids, stay in school
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Hi Bill,
Thank you very much, I don't need the source, I got the idea...
Thank you again.
Cem Louis
|
|
|
|
|
Hello,
I am interested in creating a program to handle large a mailing list and help eliminated bounced messages by doing e-mail validation. I've looked at articles on this site and elsewhere on the web, and it appears that most of the validation approaches include validating the e-mail address syntax with regular expressions, then validating that the domain exists, then connecting to the smtp server and making sure that it will accept mail for a certain address. However, I have read that this will not work for some e-mail providers, such as aol, hotmail, servers based on ms outlook, etc. and that the only way to find out if an e-mail address is really valid for these is to wait and see if the message bounces back.
Does anyone know of a sure way to validate all e-mail addresses, or is it just not possible?
I guess if there is no 100% correct way, then I can try to combine the two approaches by first checking addresses by contacting the smtp server, and then also analyzing bounced messages.
Thanks for any input.
Blake
|
|
|
|
|
I did this for a large email list, and in the end, it was mostly a waste of time. You can forget getting anything from AOL. When I tried it, hotmail and msn actually did verify the addresses. I'm not sure if that's still true.
You end up creating a fairly complicated program to handle all of the conditions (couldn't find the MX record, couldn't connect to any of the given MX's, try again later? how many times?).
You'll get so many false positives (SMTP servers that say "sure, I'll send email to fred@... when fred doesn't exist). Depending on your connection, you'll also run into servers that won't even allow you to connect ("you're on a cable modem? you have no business trying to relay mail...").
Don't get me wrong, it's a pretty fun project. Just don't expect to get too much valuable information from it .
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|