An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
You already have a valid class, so to “add task code” you don’t need to change the structure—just add an async method inside the class and make sure you import System.Threading.Tasks.
Try the following
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Maui.ApplicationModel.DataTransfer;
using Microsoft.Maui.Storage;
namespace MauiApp10_1
{
internal class Code1
{
public async Task DoSomethingAsync()
{
await Task.Delay(1000);
Console.WriteLine("Task completed");
}
}
}
If your task involves MAUI features like sharing or storage, place that logic inside the async method:
public async Task ShareTextAsync()
{
await Share.RequestAsync(new ShareTextRequest
{
Text = "Hello from MAUI",
Title = "Share"
});
}
If this method needs to be called from UI (like a button), make sure the caller is also async:
await new Code1().DoSomethingAsync();
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin