PDA

View Full Version : سوال: break شدن برنامه در زمان استفاده از کلاس



ravaei
یک شنبه 07 دی 1393, 14:46 عصر
درود . اول error رو متنشو می زارم احساس می کنم به خاطر کم تجربگیه تاحالا با این حالت روبرو نشدم.


A first chance exception of type 'System.NotImplementedException' occurred in WindowsFormsApplication23.exe
Additional information: The method or operation is not implemented.
If there is a handler for this exception, the program may be safely continued.

یه کلاس نوشتم که کدشو پایین میزارم هروقت به نحوی از این کلاس استفاده می کنم برنامه break میشه و پیغام بالا رو میده که دو گزینه break و countinue رو داره .


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Instrumentation;
namespace WindowsFormsApplication23
{
class connecting
{
public bool connectioninfo()
{

bool cnt=false;
ManagementObjectSearcher deviceList = new ManagementObjectSearcher("Select Name, Status from Win32_PnPEntity");
foreach (ManagementObject device in deviceList.Get())
{
string name = device.GetPropertyValue("Name").ToString();
if (name == "Apple Mobile Device USB Driver" || name == "SAMSUNG Mobile USB Composite Device")
{
cnt = true;
}


}
if (cnt == true) return true;
else return false;
}
}
}

در آخر هم وقتی Break رو میزنم به این کد گیر میده .



throw new NotImplementedException();

parvizwpf
یک شنبه 07 دی 1393, 15:06 عصر
ببینید این خط آخر throw در واقع خودش ایجاد اکسپشن میکنه هر جا هست بجاش ارور منطقی خودتون رو بزارید و یا اینکه بررسی کنید چرا برنامه اونجا رو اجرا میکنه.

ravaei
یک شنبه 07 دی 1393, 16:51 عصر
ببینید این خط آخر throw در واقع خودش ایجاد اکسپشن میکنه هر جا هست بجاش ارور منطقی خودتون رو بزارید و یا اینکه بررسی کنید چرا برنامه اونجا رو اجرا میکنه.


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


foreach (ManagementObject device in deviceList.Get())

یعنی وقتی اینو
throw new NotImplementedException();

پاک میکنم به .get تو forech گیر میده و دوبازه باید بسازه .

اگه امکانش هست یخورده بیشتر توضیح بدید