Tôi nhận được ngoại lệ này:
NullReferenceNgoại lệ
Object reference not set to an instance of an object
tại Namespace.TheClass.TheMethod()
tại System.Threading.ThreadHelper.ThreadStart_Context(Trạng thái đối tượng)
tại System.Threading.ExecutionContext.runTryCode(Object userData)
tại System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(mã TryCode, CleanupCode backoutCode, Object userData)
tại System.Threading.ExecutionContext.RunInternal(ExecutionContext thực thiContext, gọi lại ContextCallback, trạng thái đối tượng)
tại System.Threading.ExecutionContext.Run(ExecutionContext thực thiContext, gọi lại ContextCallback, trạng thái đối tượng, Boolean ignSyncCtx)
tại System.Threading.ExecutionContext.Run(ExecutionContext thực thiContext, gọi lại ContextCallback, trạng thái đối tượng)
tại System.Threading.ThreadHelper.ThreadStart()
Trong mã này:
lớp công khai TheClass : TheBaseClass
{
Danh sách IList1 được bảo vệ;
đối tượng công cộng Object1;
public ManualResetEvent MrEvent = new ManualResetEvent(false);
chỉ đọc Attr1 Attr1;
chỉ đọc Attr2 Attr2;
chỉ đọc EventHandler BeginHandler, EndHandler;
EventHandler Handler2 chỉ đọc;
EventHandler Handler3 chỉ đọc;
public TheClass(Attr1 attr1, Attr2 attr2, EventHandler BeginHandler, EventHandler endHandler, EventHandler handler2, EventHandler handler3)
{
this.Attr1 = attr1;
this.Attr2 = attr2;
this.BeginHandler = BeginHandler;
this.EndHandler = endHandler;
this.Handler2 = handler2;
this.Handler3 = handler3;
Chủ đề t = Chủ đề mới (Chạy);
t.IsBackground = true;
t.Start();
}
voidTheMethod()
{
Args1 args1 = new Args1();
nếu (BeginHandler != null)
{
thử
{
BeginHandler(cái này, args1);
}
catch { }
}
thử
{
Danh sách = GetList(args1);
}
catch { }
nếu (Danh sách != null)
{
List.Event1 += new EventHandler(List_Event1);
}
nếu (Handler3 != null)
{
thử
{
Args3 args3 = Args3 mới(args1.Attr1, args1.Attr2);
Handler3(cái này, args3);
this.Object1 = args3.Object1;
}
catch { }
}
if (this.Object1 == null)
{
nếu (args1.Attr1 != null)
thử
{
this.Object1 = Class4.GetObject(args1.Attr1);
}
catch { }
}
MrEvent.Set();
Phương thức1();
Phương thức2();
nếu (Danh sách != null)
{
List.Event1 -= new EventHandler(List_Event1);
}
nếu (EndHandler != null)
{
thử
{
EndHandler(cái này, args1);
}
catch { }
}
}
}
Tôi không thấy bất cứ nơi nào có thể ném ngoại lệ null xử lý ở trên. Bạn có nhìn thấy ai không?
Veer: Làm sao bạn có thể thay đổi ý nghĩa câu hỏi của tôi nhiều đến vậy?
Đối với những người đồng ý với nó: Làm sao bạn có thể đồng ý với nó?
NullReferenceException có thể được ném ra từ các phương thức nội tuyến. Kiểm tra Phương pháp 1 và Phương pháp 2.
Tôi là một lập trình viên xuất sắc, rất giỏi!