This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Path Fill="#FF3B30" | |
Data="M 18,6 C 14.5,3.5 9,3.5 6,7 3,10.5 3,16.5 6,20 9,23.5 36,47 36,47 36,47 63,23.5 66,20 69,16.5 69,10.5 66,7 63,3.5 57.5,3.5 54,6 36,24 18,6 Z" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Debugger.IsAttached) | |
Debugger.Break(); // Pauses only when debugging |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async Task LoadDataAndUpdateUI() | |
{ | |
var data = await FetchDataInBackground(); // Runs in background | |
MainThread.BeginInvokeOnMainThread(() => | |
{ | |
myLabel.Text = $"Loaded {data.Count} items"; // Safe UI update | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int retryCount = 0; | |
while (!success && retryCount < 5) | |
{ | |
try | |
{ | |
await SyncData(); | |
success = true; | |
} | |
catch (Exception ex) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = new BackgroundTaskBuilder(); | |
builder.Name = "DataSyncTask"; | |
builder.TaskEntryPoint = "MyApp.BackgroundTasks.DataSyncTask"; | |
builder.SetTrigger(new TimeTrigger(15, false)); // Every 15 mins | |
BackgroundTaskRegistration task = builder.Register(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var constraints = new Constraints.Builder() | |
.SetRequiredNetworkType(NetworkType.Connected) | |
.SetRequiresBatteryNotLow(true) | |
.Build(); | |
var workRequest = new OneTimeWorkRequest.Builder<MyWorker>() | |
.SetConstraints(constraints) | |
.SetInitialDelay(TimeSpan.FromMinutes(10)) | |
.Build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BackgroundTasks; | |
var request = new BGProcessingTaskRequest("com.yourapp.datasync"); | |
request.RequiresNetworkConnectivity = true; | |
BGTaskScheduler.Shared.Submit(request, out var error); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task.Run(async () => | |
{ | |
while (true) | |
{ | |
await Task.Delay(TimeSpan.FromMinutes(15)); // Run every 15 mins | |
await SyncData(); // Custom sync logic | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddTransient<ServiceProxy>(); | |
services.AddTransient<IService>(sp => | |
sp.GetRequiredService<ServiceProxy>().Create<RealService>()); | |
public class ServiceProxy | |
{ | |
public T Create<T>() where T : class | |
{ | |
return DispatchProxy.Create<T, LoggingInterceptor>(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SessionLifetime : IServiceScopeFactory | |
{ | |
private readonly ConcurrentDictionary<string, IServiceScope> _scopes = new(); | |
public IServiceScope CreateScopeForSession(string sessionId) | |
{ | |
return _scopes.GetOrAdd(sessionId, | |
id => Services.BuildServiceProvider().CreateScope()); | |
} | |
} |