Telegram Group & Telegram Channel
به نحوه ی صدا زدن دو تابع زیر دقت کنید:
new Task(async () => throw new NotImplementedException()).Start();

Task.Run(async () => throw new NotImplementedException());


اتفاقی که بعد از اجرا میوفته:
توی تابع اول اپلیکیشن شما کرش میکنه و به طور کامل با خطای unhandled exception بسته میشه.
توی تابع دوم اپلیکیشن شما به راه خودش ادامه میده.

چرا این اتفاق میوفته؟
چون سازنده ی Task متد Func<Task?> رو پیاده سازی نکرده، این یعنی ورودی شما به عنوان کانستراکتور یا سازنده مستقیم به یک Action تبدیل شده و وارد سازنده ی کلاس میشه.وقتی شما به یک Action ورودی async میدید این درواقع برای شما مثل یک تابع async void عمل میکنه و اگر Exception ای اونجا رخ بده چون هیچکجا هندل نشده و باعث میشه اپ شما کرش کنه.
راه کارش اینه که شما try catch بذارید و جلوی این مشکل رو بگیرید.

اما روش بهینه اش اینه که بذارید توسط خود Task.Run این اتفاق بیوفته چون خود Task خطاهارو به نحوی هندل میکنه که unhandled exception نخورید و باعث میشه اپ شما کرش نکنه اما لاگ کردن این نوع خطاها نیازمند یک کلاس Helper هست که با پیاده سازیش خودتون میتونید توی کارهای پس زمینه ی خودتون لاگ بذارید که اگر خطایی خورد متوجه عملکرد نرم افزار بشید.

پس مراقب باشید که چطوری از Task استفاده می کنید.

#تخصصی
#سی_شارپ
#تسک
#Task
#Thread

کانال تلگرام:
@CsharpTips



tg-me.com/CsharpTips/349
Create:
Last Update:

به نحوه ی صدا زدن دو تابع زیر دقت کنید:

new Task(async () => throw new NotImplementedException()).Start();

Task.Run(async () => throw new NotImplementedException());


اتفاقی که بعد از اجرا میوفته:
توی تابع اول اپلیکیشن شما کرش میکنه و به طور کامل با خطای unhandled exception بسته میشه.
توی تابع دوم اپلیکیشن شما به راه خودش ادامه میده.

چرا این اتفاق میوفته؟
چون سازنده ی Task متد Func<Task?> رو پیاده سازی نکرده، این یعنی ورودی شما به عنوان کانستراکتور یا سازنده مستقیم به یک Action تبدیل شده و وارد سازنده ی کلاس میشه.وقتی شما به یک Action ورودی async میدید این درواقع برای شما مثل یک تابع async void عمل میکنه و اگر Exception ای اونجا رخ بده چون هیچکجا هندل نشده و باعث میشه اپ شما کرش کنه.
راه کارش اینه که شما try catch بذارید و جلوی این مشکل رو بگیرید.

اما روش بهینه اش اینه که بذارید توسط خود Task.Run این اتفاق بیوفته چون خود Task خطاهارو به نحوی هندل میکنه که unhandled exception نخورید و باعث میشه اپ شما کرش نکنه اما لاگ کردن این نوع خطاها نیازمند یک کلاس Helper هست که با پیاده سازیش خودتون میتونید توی کارهای پس زمینه ی خودتون لاگ بذارید که اگر خطایی خورد متوجه عملکرد نرم افزار بشید.

پس مراقب باشید که چطوری از Task استفاده می کنید.

#تخصصی
#سی_شارپ
#تسک
#Task
#Thread

کانال تلگرام:
@CsharpTips

BY C# Programming Guide


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/CsharpTips/349

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

Find Channels On Telegram?

Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.

That growth environment will include rising inflation and interest rates. Those upward shifts naturally accompany healthy growth periods as the demand for resources, products and services rise. Importantly, the Federal Reserve has laid out the rationale for not interfering with that natural growth transition.It's not exactly a fad, but there is a widespread willingness to pay up for a growth story. Classic fundamental analysis takes a back seat. Even negative earnings are ignored. In fact, positive earnings seem to be a limiting measure, producing the question, "Is that all you've got?" The preference is a vision of untold riches when the exciting story plays out as expected.

telegram from hk


Telegram C# Programming Guide
FROM USA