Skip to content

Instantly share code, notes, and snippets.

View luisdeol's full-sized avatar
🎯
Focusing

Luis Felipe de Oliveira luisdeol

🎯
Focusing
View GitHub Profile
@luisdeol
luisdeol / volatileVariable.cs
Created November 19, 2017 19:08
Using the volatile keyword
private static volatile int _theValue;
@luisdeol
luisdeol / Program.cs
Created November 19, 2017 19:21
Using the Interlocked Class
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
int theAlmightyZero = 0;
object _lockTheSavior = new object();
Task newAmazingTask = Task.Run(() =>
@luisdeol
luisdeol / Program.cs
Created November 19, 2017 19:37
Using the CancellationToken
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
CancellationToken token = cancellationTokenSource.Token;
int theCount = 0;
Console.WriteLine("Task running...Count from 0 to...");
@luisdeol
luisdeol / Program.cs
Created November 19, 2017 20:06
Using ContinueWith and Cancellation of a Task
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
CancellationToken token = cancellationTokenSource.Token;
int theCount = 0;
Console.WriteLine("Task running...Count from 0 to...");
@luisdeol
luisdeol / Program.cs
Created November 19, 2017 20:13
Using ContinueWith and Cancellation of a Task
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
CancellationToken token = cancellationTokenSource.Token;
int theCount = 0;
Console.WriteLine("Task running...Count from 0 to...");
@luisdeol
luisdeol / Program.cs
Created November 19, 2017 20:22
Using the TimeOut parameter of the Task.WaitAny overload
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
Task notThatPowerfulTask = Task.Run(() =>
{
Console.WriteLine("A long-running task is being executed right now...");
Thread.Sleep(10000);
@luisdeol
luisdeol / Program.cs
Last active November 29, 2017 10:39
Using the for statement to iterate across a collection
namespace implement_program_flow
{
class Program
{
static void Main(string[] args)
{
var tasks = new[] {"Analyze", "Design", "Code", "Build", "Test", "Blue screen of death", "Deploy"};
for (var i = 0; i < tasks.Length; i++)
{
var task = tasks[i];
@luisdeol
luisdeol / Program.cs
Last active November 29, 2017 10:39
Use the while and do-while to manage the program flow
namespace implement_program_flow
{
class Program
{
static void Main(string[] args)
{
var mainstreamCount = 0;
while (mainstreamCount > 0)
{
@luisdeol
luisdeol / Program.cs
Last active November 29, 2017 10:39
Use the foreach statement to iterate across a colection
namespace implement_program_flow
{
class Program
{
static void Main(string[] args)
{
var tasks = new[] { "Analyze", "Design", "Code", "Build", "Test", "Blue screen of death", "Deploy" };
foreach (var task in tasks)
{
@luisdeol
luisdeol / Program.cs
Last active November 29, 2017 10:39
Use the GoTo statement to Jump to a specific part of the code
namespace implement_program_flow
{
class Program
{
static void Main(string[] args)
{
var toJump = true;
if (toJump)