Closed Profmaxmonteiro closed 2 years ago
Hgf
I suppose this code is for checking prime numbers? You're trying to make it work in parallel? Creating pure threads essentially results in a random order of execution, but they might still print out in the app. However that is due to a limitation in the app's runtime. Any threads you start can't be terminated by the app, so they will continue after your program exits. And your program exits immediately after creating the threads - on Windows it would just close.
Also C# is case sensitive when naming stuff so "primo" != "Primo". And some of the "{" and "}" braces seem wrong. There are more errors in variable names.
This code can't be made parallel without rewriting it almost completely. And your current implementation wouldn't make it more effective without some modifications to avoid recalculations because it is parallel. See the Parallel class.
However multiple threads won't make the calculation itself faster. It is a simple mathematical operation and threading itself is a costly operation, especially when iterating. Single thread will be faster. Something like this.
using System; using System.Linq; using System.Collections.Generic; using System.Threading.Tasks; using System.Globalization;
namespace exercicio_02 { class Program { static void Main(string[] args) {
try { String entrada; int entradaConvertida = 0; do { Console.Write("Digite os dois últimos números de seu RU: "); entrada = Console.ReadLine();
}