인터넷 연결을 사용할 수 있고 연결되어 있으면 계속 진행합니다. 그렇지 않으면 연결이 불가능하다는 메시지 상자가 표시됩니다.인터넷 연결 사용 가능 여부 확인
인터넷 연결이 연결되었는지 여부에 관계없이 코드가 계속됩니다. 이
public CheckUpdates()
{
InitializeComponent();
bool checkConnection = CheckConnection.IsConnectedToInternet();
progressBar1.Style = ProgressBarStyle.Marquee;
if (checkConnection == true)
{
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.DoWork += new DoWorkEventHandler(worker_DoWork);
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
}
else
{
System.Media.SoundPlayer _sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
_sound.Play();
DialogResult _dialogResult = MessageBox.Show("No connection available, please check your internet connection!", "No connection");
if (_dialogResult == DialogResult.OK)
{
this.Hide();
this.Close();
}
}
}
private void CheckUpdates_Load(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
if (e.ProgressPercentage.Equals(100))
{
System.Media.SoundPlayer _sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
_sound.Play();
DialogResult _dialogResult = MessageBox.Show("No updates were available!", "No updates");
if (_dialogResult == DialogResult.OK)
{
this.Hide();
this.Close();
}
}
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
_timer.Enabled = true;
_timer.Tick += new EventHandler(Timer_Tick);
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 100; i++)
{
backgroundWorker1.ReportProgress(i);
System.Threading.Thread.Sleep(100);
}
}
void Timer_Tick(object sender, EventArgs e)
{
_timer.Enabled = false;
}
class CheckConnection
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
public static bool IsConnectedToInternet()
{
int Desc;
return InternetGetConnectedState(out Desc, 0);
}
}
이 이 이
의 답이 많이 주시면 감사
** 사용 가능한 인터넷 연결이없는 경우에도,이 **이 프로그램은 worker_ProgressChanged
에 계속 : 여기
대단히 감사합니다!
당신이 우리에게 보여주고있는 어떤 것도하지 않는 바보 같은 코드가 많습니다. backgroundworker 그냥 루핑입니다. 타이머가 아무 것도하지 않습니다. – LarsTech
누가 이벤트를 호출하는지 누가 알려주는지 확인하십시오. CheckUpdates_Load 또는 WelcomeScreen_Load – Steve
@Steve : WelcomeScreen_Load는 다른 양식에서 온 것입니다. Welcome 스크린에 배경 화면 작업자도 포함되어 있기 때문에 WelcomeScreen 양식의 모든 내용을 복사하여 붙여 넣기 만합니다. CheckUpdates_Load, CheckUpdates 양식을 호출하는 방법에 대해 위 코드에 표시되지 않은 CheckUpdates 양식에 연결된 단추를 클릭하면 해당 이벤트가 발생합니다. – Kaoru