---
title: "Send Scheduled SMS with C# .NET and Twilio Programmable Messaging"
excerpt: "Learn how to schedule SMS with C# .NET and Twilio Messaging's latest feature: Scheduled Messaging!"
publishDate: "2022-02-04T00:00:00"
createDate: "2022-02-04T22:54:20.45"
updateDate: "2022-02-04T23:38:10.43"
category: "dotnet"
categoryName: ".NET"
tags: [".NET",".NET Core","C#","Twilio","SMS"]
permalink: "/blog/dotnet/send-scheduled-sms-with-csharp-dotnet-and-twilio-programmable-messaging"
canonical: "https://www.twilio.com/en-us/blog/send-scheduled-sms-with-csharp-dotnet-and-twilio-programmable-messaging"
image: {"src":"/media/5xff4abe/send-scheduled-sms-with-c-net-and-twilio-canonical.png","focalPoint":{"left":0.5,"top":0.5},"crops":[{"alias":"Banner","width":1120,"height":400,"coordinates":null}]}
imageAlt: "Send Scheduled SMS with C# .NET and Twilio"
imageBackgroundColor: "#fff"
thumbnailImage: {"src":"/media/vgye2zpp/twilio-mark-red-e1886ea5f.svg","focalPoint":{"left":0.5,"top":0.5},"crops":[{"alias":"thumbnail","width":250,"height":250,"coordinates":null}]}
thumbnailImageAlt: "Twilio logo"
metaTitle: "Send Scheduled SMS with C# .NET and Twilio Programmable Messaging"
metaDescription: "Learn how to schedule SMS with C# .NET and Twilio Messaging's latest feature: Scheduled Messaging!"
ogTitle: "Send Scheduled SMS with C# .NET and Twilio Programmable Messaging"
ogDescription: "Learn how to schedule SMS with C# .NET and Twilio Messaging's latest feature: Scheduled Messaging!"
ogImage: {"src":"/media/3fqp0zy1/send-scheduled-sms-with-c-net-and-twilio-canonical.png","focalPoint":{"left":0.5,"top":0.5},"crops":[{"alias":"OpenGraph","width":1200,"height":630,"coordinates":null}]}
ogImageAlt: "Send Scheduled SMS with C# .NET and Twilio"
relatedPostKeys: ["1710543d71f748eba82e9c6891718211","a89a2292cfb440e2983284548af2aee9","99831c3f1722477fa6329b6a946bd961","5e0e8a58881040429d6f962f54471677"]
noIndex: false
noFollow: false
sitemapExclude: true
source: {"nodeId":1585,"contentKey":"6559e21fdf8d4d1db0ed93972ccc697e","sortOrder":124}
---


**This blog post was written for [Twilio](https://www.twilio.com/) and originally published at [the Twilio blog](https://www.twilio.com/blog/send-scheduled-sms-with-csharp-dotnet-and-twilio-programmable-messaging).**


Twilio [Programmable Messaging](https://www.twilio.com/messaging-api) lets you send SMS, MMS, and WhatsApp messages, but up until now, you couldn't schedule messages ahead of time. If you wanted to send messages in the future, you would have to store the message in some data store and then use [cron](https://en.wikipedia.org/wiki/Cron) jobs or write some other complicated code to deliver your messages at the right time.


Lucky for you, Programmable Messaging now supports [Message Scheduling](https://www.twilio.com/blog/message-scheduling-public-beta)! With it, you can schedule SMS messages with a single API call. No need for your own complicated scheduling infrastructure.


In this tutorial, you’ll learn how to schedule SMS's using C# and .NET.

## Prerequisites {#prerequisites}

You will need these items to follow along:


-   An OS that supports .NET (Windows/macOS/Linux)
-   [.NET 6 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
-   A code editor or IDE (I recommend VS Code with [the C# plugin](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp), [Visual Studio](https://visualstudio.microsoft.com/), or [JetBrains Rider](https://www.jetbrains.com/rider/))
-   A free or paid Twilio account (If you [register here](https://www.twilio.com/referral/OhKZOM), you'll receive $10 in Twilio credit when you upgrade to a paid account!)
-   A phone to receive the SMS's




<p class="panel panel--info">You can use older versions of .NET, including .NET framework, but you may need to make slight adjustments. For example, instead of using top-level statements, you may need to put the code in the <code>Program.Main</code> method of your console app.</p>




You can find [the source code for this tutorial on GitHub](https://github.com/Swimburger/ScheduleSmsDotNet). Use the source code if you run into any issues, or submit an issue on this GitHub repo if you run into problems.




## Buy a Twilio phone number {#buy-a-twilio-phone-number}




If you haven't done so already, you'll need to buy a Twilio phone number. To do that, log in to the [Twilio Console](https://console.twilio.com/), select [Phone Numbers](https://console.twilio.com/us1/develop/phone-numbers/manage/active?frameUrl=/console/phone-numbers/incoming), and then click on the “**Buy a number**” button. Note that if you have a free account, you will be using your trial credit for this purchase.





On the “Buy a Number” page, select your country and check SMS in the “**Capabilities**” field. If you’d like to request a number that is local to your region, you can enter your area code in the “**Number**” field.




<p><img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/6HHWGoeCIw0vQyXNll7z2w8A_8WcfAcKxGljb41t5-vJ5S.width-500.png" alt="Buy a Twilio phone number" width="500" height="209"></p>




Click the “**Search**” button to see what numbers are available, and then click “**Buy**” for the number you like from the results. After you confirm your purchase, click the “**Close**” button.




## Configure a Messaging Service {#configure-a-messaging-service}




<strong>Scheduled messages can only be sent from a </strong><a href="https://www.twilio.com/docs/messaging/services"><strong>Messaging Service</strong></a><strong> at this time</strong>, so the next step is to configure a Messaging Service and add your Twilio phone number to it.





In the Twilio Console, find the “Messaging” product and click on its [Services](https://console.twilio.com/us1/develop/sms/services?frameUrl=%2Fconsole%2Fsms%2Fservices%3Fx-target-region%3Dus1) option. Then click the “**Create Messaging Service**” button.





On the first page of the creation process, enter a friendly name for the service, such as “Appointments”, and select “**Notify my users**” in the “**Select what you want to use Messaging for**” dropdown.




<p><img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/OMf7Iy9u65pHZZCCFXf4GtCaRZclJolykJDmRcDJKzBDX0.width-500.png" alt="Create messaging service page 1" width="500" height="301"></p>




Click the “**Create Messaging Service**” button to move to the second step. In this part of the configuration, you have to add the sender phone number(s) to the sender pool used by the service. Click the “**Add Senders**” button to add the Twilio phone number you acquired in the previous section.




<p><img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/-BEf0-SgYXV4F2os9FrZVW_bsGydemvAmQHxglHQK8Fe4u.width-500.png" alt="Create messaging service part 2" width="500" height="343"></p>




Select **Phone Number** in the “**Sender Type**” dropdown, and click “**Continue**”.





Add a checkmark next to the phone number you want to use as a sender, and click “**Add phone numbers**”.




<p><img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/5lg-MglPe3dIYupGRvTDs54fGBlrtiYhq187eJVL8WpktH.width-500.png" alt="Add senders to messaging service" width="500" height="341"></p>




Click the “**Step 3: Set up integration**” button to move on to the next step. You don’t have to change any of the settings on this page, just click on “**Step 4: Add compliance info**”.


To complete the configuration of your Messaging Service, click on “Complete Messaging Service Setup”. You will now be offered the option to send a test message.

<p><img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/hIG6wzVD4esl1l3tfR4PQMOtnXLJk8ndMPlSajgqbmJ8Bk.width-500.png" alt="Messaging service setup complete" width="500" height="250"></p>




It is a good idea to test that your messaging service is able to send messages, so go ahead and click on “**Try sending a message**”.





In the “**To phone number**” dropdown, select your personal number, which should be [registered and verified with your Twilio account](https://support.twilio.com/hc/en-us/articles/223180048-Adding-a-Verified-Phone-Number-or-Caller-ID-with-Twilio). Select the Messaging Service you just created in the “**From Messaging Service SID**”. Enter some text to send yourself in the “**Body Text**”.





<img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/gvNquy__xixc0dMKjPGWqB5TWoywZAS4hoeAg7K1Vn-el2.width-500.png" alt="Send test SMS" width="500" height="415"><br><br>





Click the “**Send test SMS**” button, and make sure you receive the SMS on your phone.




## Send Scheduled SMS with C# and .NET {#send-scheduled-sms-with-c-and-net}

Now that you have a Twilio phone number and Messaging Service, you can get started with the .NET application. Open your preferred shell, then run these commands to create a new folder *ScheduleSmsDotNet* and navigate to it:

<pre style="color:#000000;background:#ffffff;">mkdir ScheduleSmsDotNet&#10;<span style="color:#7f0055; font-weight:bold; ">cd</span> ScheduleSmsDotNet&#10;</pre>

Next, use the .NET CLI to create a new console project:

<pre style="color:#000000;background:#ffffff;">dotnet new console&#10;</pre>

You can use the [Twilio SDK for C# and .NET](https://www.twilio.com/docs/libraries/csharp-dotnet) to easily interact with Twilio's APIs. Add the Twilio SDK using the [Twilio NuGet package](https://www.nuget.org/packages/Twilio/) by running the command below:

<pre style="color:#000000;background:#ffffff;">dotnet add package Twilio&#10;</pre>



<p class="panel panel--info">At the time of writing this, the version of the Twilio NuGet package is 5.70.0. Earlier versions will not contain the new APIs for scheduling messages.</p>

Open *Program.cs* in your preferred editor and replace it with the following code:

<pre style="color:#000000;background:#ffffff;"><span style="color:#7f0055; font-weight:bold; ">using</span> System;&#10;<span style="color:#7f0055; font-weight:bold; ">using</span> Twilio;&#10;<span style="color:#7f0055; font-weight:bold; ">using</span> Twilio.Types;&#10;<span style="color:#7f0055; font-weight:bold; ">using</span> Twilio.Rest.Api.V2010.Account;&#10;&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioAccountSid = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioAccountSid</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioAuthToken = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioAuthToken</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioMessagingServiceSid = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioMessagingServiceSid</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> toPhoneNumber = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">ToPhoneNumber</span><span style="color:#2a00ff; ">"</span>);&#10;&#10;TwilioClient.Init(twilioAccountSid, twilioAuthToken);&#10;&#10;<span style="color:#7f0055; font-weight:bold; ">var</span> message = MessageResource.Create(&#10;    messagingServiceSid: twilioMessagingServiceSid,&#10;    body: <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Sending SMS with Twilio and .NET is easy!</span><span style="color:#2a00ff; ">"</span>,&#10;    to: <span style="color:#7f0055; font-weight:bold; ">new</span> PhoneNumber(toPhoneNumber)&#10;);&#10;&#10;Console.WriteLine($<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Message SID: {message.Sid}</span><span style="color:#2a00ff; ">"</span>);&#10;</pre>

This application fetches the Twilio Account SID, the Twilio Auth Token, the SID of your Messaging Service, and your phone number from the environment variables. It then initializes the `TwilioClient` using the Account SID and Auth Token to authenticate. Lastly, it **sends an SMS immediately** to your phone number from the phone number you configured in your Messaging Service.

Before you can run this program, you'll need to set those environment variables. Switch back to your shell and use the following commands to set the environment variables.


If you're using **Bash or a similar shell**:




<pre style="color:#000000;background:#ffffff;"><span style="color:#7f0055; font-weight:bold; ">export</span> TwilioAccountSid=<span style="color:#2a00ff; ">[</span><span style="color:#2a00ff; ">TWILIO_ACCOUNT_SID</span><span style="color:#2a00ff; ">]</span>&#10;<span style="color:#7f0055; font-weight:bold; ">export</span> TwilioAuthToken=TWILIO_AUTH_TOKEN]&#10;<span style="color:#7f0055; font-weight:bold; ">export</span> TwilioMessagingServiceSid=<span style="color:#2a00ff; ">[</span><span style="color:#2a00ff; ">TWILIO_MESSAGING_SERVICE_SID</span><span style="color:#2a00ff; ">]</span>&#10;<span style="color:#7f0055; font-weight:bold; ">export</span> ToPhoneNumber=<span style="color:#2a00ff; ">[</span><span style="color:#2a00ff; ">YOUR_PHONE_NUMBER</span><span style="color:#2a00ff; ">]</span>&#10;</pre>




If you're using **PowerShell**:




<pre style="color:#000000;background:#ffffff;">$Env:TwilioAccountSid = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">[TWILIO_ACCOUNT_SID]</span><span style="color:#2a00ff; ">"</span>&#10;$Env:TwilioAuthToken = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">[TWILIO_AUTH_TOKEN]</span><span style="color:#2a00ff; ">"</span>&#10;$Env:TwilioMessagingServiceSid = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">[TWILIO_MESSAGING_SERVICE_SID]</span><span style="color:#2a00ff; ">"</span>&#10;$Env:ToPhoneNumber = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">[YOUR_PHONE_NUMBER]</span><span style="color:#2a00ff; ">"</span>&#10;</pre>




If you're using **CMD**:




<pre style="color:#000000;background:#ffffff;"><span style="color:#7f0055; font-weight:bold; ">set</span> <span style="color:#2a00ff; ">"TwilioAccountSid=[TWILIO_ACCOUNT_SID]"</span>&#10;<span style="color:#7f0055; font-weight:bold; ">set</span> <span style="color:#2a00ff; ">"TwilioAuthToken=[TWILIO_AUTH_TOKEN]"</span>&#10;<span style="color:#7f0055; font-weight:bold; ">set</span> <span style="color:#2a00ff; ">"TwilioMessagingServiceSid=[TWILIO_MESSAGING_SERVICE_SID]"</span>&#10;<span style="color:#7f0055; font-weight:bold; ">set</span> <span style="color:#2a00ff; ">"ToPhoneNumber=[YOUR_PHONE_NUMBER]"</span>&#10;</pre>




Make sure to **replace the placeholders in the script above**. The first two placeholders are your Twilio “**Account SID**” and your “**Auth Token**”. You can find them in the dashboard of the main page of the [Twilio Console](https://console.twilio.com/), under “Account Info”:




<p><img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/BYdY44BEWvqW1i6q1nqkNlesklaTqvlAoOORgoRJa8OcfE.width-500.png" alt="Account Info box holding 3 read-only fields: Account SID field, Auth Token field, and Twilio phone number field." width="500" height="275"></p>




The `[TWILIO_MESSAGING_SERVICE_SID]` placeholder is the `SID` assigned to the Messaging Service. You can find it in the [Messaging Services](https://console.twilio.com/us1/develop/sms/services?frameUrl=%2Fconsole%2Fsms%2Fservices%3Fx-target-region%3Dus1) page of the Twilio Console. This identifier starts with the letters `MG`.


Now that the environment variables are present, you can run the application using the .NET CLI:

<pre style="color:#000000;background:#ffffff;">dotnet run&#10;</pre>




If all goes well, you'll receive an SMS on your phone and the application outputs something looking like this: `Message SID: SM54a40e2fc2b443fb97b514ab79d36127`.





To schedule an SMS to be sent in the future, you'll need to add two extra parameters to the `MessageResource.Create` method. To do that, update `Program.cs`, by adding the highlighted lines in the code below:




<pre style="color:#000000;background:#ffffff;"><span style="color:#7f0055; font-weight:bold; ">using</span> Twilio;&#10;<span style="color:#7f0055; font-weight:bold; ">using</span> Twilio.Types;&#10;<span style="color:#7f0055; font-weight:bold; ">using</span> Twilio.Rest.Api.V2010.Account;&#10;&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioAccountSid = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioAccountSid</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioAuthToken = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioAuthToken</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioMessagingServiceSid = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioMessagingServiceSid</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> toPhoneNumber = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">ToPhoneNumber</span><span style="color:#2a00ff; ">"</span>);&#10;&#10;TwilioClient.Init(twilioAccountSid, twilioAuthToken);&#10;&#10;<span style="color:#7f0055; font-weight:bold; ">var</span> message = MessageResource.Create(&#10;    messagingServiceSid: twilioMessagingServiceSid,&#10;    body: <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Sending SMS with Twilio and .NET is easy!</span><span style="color:#2a00ff; ">"</span>,&#10;    to: <span style="color:#7f0055; font-weight:bold; ">new</span> PhoneNumber(toPhoneNumber),&#10;    sendAt: DateTime.UtcNow.AddMinutes(61),&#10;    scheduleType: MessageResource.ScheduleTypeEnum.Fixed&#10;);&#10;&#10;Console.WriteLine($<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Message SID: {message.Sid}</span><span style="color:#2a00ff; ">"</span>);&#10;</pre>




The `sendAt` parameter specifies when the message will be sent. The parameter expects an instance of `DateTime` and it has to be expressed using [Coordinated Universal Time (UTC)](https://www.timeanddate.com/time/aboututc.html).<br><br>




<p class="panel panel--warning">Any scheduled message has to be scheduled at least later than 1 hour (3600 seconds) from now, and before 7 days from now.  There is a delay between when the <code>DateTime</code> instance is created and when Twilio receives the <code>MessageResource</code> on their servers. For example, if you create a <code>DateTime</code> exactly 3600 seconds from now, by the time Twilio receives your API request, the <code>DateTime</code> may be 2599 or fewer seconds from now. In that case, the Twilio API will reject your request.</p>




<br>To make sure your scheduled message is within the supported range, you can account for the delay if needed, by adding extra seconds or a minute to your `DateTime`.


Lastly, the `scheduleType` parameter configures the type of scheduling that you want to use. At the time of writing, `Fixed` is the only available enum value.


To test out your application, run your project again: 




<pre style="color:#000000;background:#ffffff;">dotnet run&#10;</pre>




The output should be the same, but you will not receive a text message immediately. You'll have to wait 61 minutes to receive the message. However, in the meantime, you can view the message in the [Programmable Messaging Logs](https://console.twilio.com/us1/monitor/logs/sms?frameUrl=%2Fconsole%2Fsms%2Flogs%3Fx-target-region%3Dus1&currentFrameUrl=%2Fconsole%2Fsms%2Flogs%3F__override_layout__%3Dembed%26bifrost%3Dtrue%26x-target-region%3Dus1) section of the Twilio Console, under which the message will show with its status set to “**Scheduled**” until the time of delivery.




<p><img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/O26rEKQBC6TQRUrYgukZdKcIi5Tk5iFVIIf4T7oBIuj6BJ.width-500.png" alt="Programmable Messaging Logs before delivery" width="500" height="131"></p>




When the hour passes and your SMS is delivered, the status of the message will change to “**Delivered**”. You will also be able to see your Twilio phone number as the sender.




<p><img class="richtext-image left" src="https://twilio-cms-prod.s3.amazonaws.com/images/TY4eGEH5ygiTWBJ1_O2EGJKYt6Mwo6dvZSgI998MuJ-Eq8.width-500.png" alt="Programmable Messaging Logs after delivery" width="500" height="132"></p>



## Cancel a Scheduled SMS with C# and .NET {#cancel-a-scheduled-sms-with-c-and-net}




If at some point you need to cancel a scheduled message, you can do so as long as it hasn't been delivered yet. 


To try this out, update your `Program.cs` file as follows:

<pre style="color:#000000;background:#ffffff;"><span style="color:#7f0055; font-weight:bold; ">using</span> Twilio;&#10;<span style="color:#7f0055; font-weight:bold; ">using</span> Twilio.Types;&#10;<span style="color:#7f0055; font-weight:bold; ">using</span> Twilio.Rest.Api.V2010.Account;&#10;&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioAccountSid = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioAccountSid</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioAuthToken = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioAuthToken</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> twilioMessagingServiceSid = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">TwilioMessagingServiceSid</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">string</span> toPhoneNumber = Environment.GetEnvironmentVariable(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">ToPhoneNumber</span><span style="color:#2a00ff; ">"</span>);&#10;&#10;TwilioClient.Init(twilioAccountSid,twilioAuthToken);&#10;&#10;Console.Write(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Do you want to schedule an SMS? (y/n)</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">if</span> (<span style="color:#7f0055; font-weight:bold; ">string</span>.Equals(Console.ReadLine(), <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">y</span><span style="color:#2a00ff; ">"</span>, StringComparison.OrdinalIgnoreCase))&#10;{&#10;    <span style="color:#7f0055; font-weight:bold; ">var</span> message = MessageResource.Create(&#10;        messagingServiceSid: twilioMessagingServiceSid,&#10;        body: <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Sending SMS with Twilio and .NET is easy!</span><span style="color:#2a00ff; ">"</span>,&#10;        to: <span style="color:#7f0055; font-weight:bold; ">new</span> PhoneNumber(toPhoneNumber),&#10;        sendAt: DateTime.UtcNow.AddMinutes(61),&#10;        scheduleType: MessageResource.ScheduleTypeEnum.Fixed&#10;    );&#10;    Console.WriteLine($<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Message SID: {message.Sid}</span><span style="color:#2a00ff; ">"</span>);&#10;}&#10;&#10;Console.Write(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Do you want to cancel a scheduled SMS? (y/n)</span><span style="color:#2a00ff; ">"</span>);&#10;<span style="color:#7f0055; font-weight:bold; ">if</span> (<span style="color:#7f0055; font-weight:bold; ">string</span>.Equals(Console.ReadLine(), <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">y</span><span style="color:#2a00ff; ">"</span>, StringComparison.OrdinalIgnoreCase))&#10;{&#10;    Console.Write(<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Enter message SID:</span><span style="color:#2a00ff; ">"</span>);&#10;    <span style="color:#7f0055; font-weight:bold; ">string</span> messageSid = Console.ReadLine();&#10;&#10;    <span style="color:#7f0055; font-weight:bold; ">var</span> messages = MessageResource.Update(pathSid: messageSid, status: MessageResource.UpdateStatusEnum.Canceled);&#10;    Console.WriteLine($<span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Scheduled SMS canceled</span><span style="color:#2a00ff; ">"</span>);&#10;}&#10;</pre>

The application will now ask you if you want to schedule a message. If you enter 'y', it will schedule the message as before. Then, it will ask if you want to cancel a scheduled message. If you enter 'y', it will ask you for the SID of the message. If you enter the message SID, it will go ahead and cancel the scheduled message, by updating the status to `Canceled` on line 31.

Run the application again:

<pre style="color:#000000;background:#ffffff;">dotnet run&#10;</pre>

Enter 'y', then copy the SID of the newly scheduled message, enter 'y' again, and then paste in the message SID. The application will now cancel the scheduled message.

## Next steps {#next-steps}

Congratulations on learning how to send scheduled SMS with .NET and C#! Here are a number of resources on scheduling SMS that you may want to review to learn more:


-   [How to schedule a message](https://www.twilio.com/docs/sms/api/message-resource#schedule-a-message-resource) (API documentation)
-   [How to cancel a scheduled message](https://www.twilio.com/docs/sms/api/message-resource#cancel-a-scheduled-message) (API documentation)
-   [Message Scheduling Public Beta announcement](https://www.twilio.com/blog/message-scheduling-public-beta)
-   [Message Scheduling FAQs and Beta Limitations](https://support.twilio.com/hc/en-us/articles/4412165297947-Message-Scheduling-FAQs-and-Beta-Limitations)


We can't wait to see what you'll build with Twilio and Message Scheduling!
