74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace WpfApp1
|
|
{
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows.Controls;
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
public class MainWindowViewModel : ObservableObject
|
|
{
|
|
private RelayCommand _openDialogCommand;
|
|
private IRelayCommand _testMultiStreamingCommand;
|
|
|
|
public IRelayCommand OpenDialogCommand =>
|
|
_openDialogCommand ??= new RelayCommand(OpenDialog);
|
|
|
|
public ReadOnlyObservableCollection<UserControl> Dialogs => DialogService.Instance.Dialogs;
|
|
|
|
public IRelayCommand TestMultiStreamingCommand =>
|
|
_testMultiStreamingCommand ??= new AsyncRelayCommand(TestMultiStreaming);
|
|
|
|
private async Task TestMultiStreaming()
|
|
{
|
|
try
|
|
{
|
|
const string path = @"C:\Users\Holger\Desktop\WpfApp1.txt";
|
|
using var openFile1 = new FileStream(
|
|
path,
|
|
FileMode.Create,
|
|
FileAccess.Write,
|
|
FileShare.ReadWrite
|
|
);
|
|
using var writer1 = new StreamWriter(openFile1, Encoding.Unicode);
|
|
await writer1.WriteLineAsync($"{DateTime.Now:O} Hello from Writer 1");
|
|
await writer1.FlushAsync();
|
|
using var openFile2 = new FileStream(
|
|
path,
|
|
FileMode.Open,
|
|
FileAccess.Read,
|
|
FileShare.ReadWrite
|
|
);
|
|
using var reader = new StreamReader(openFile2, Encoding.Unicode);
|
|
var content = await reader.ReadToEndAsync();
|
|
MessageBox.Show(content);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
MessageBox.Show(e.Message);
|
|
}
|
|
}
|
|
|
|
private static void OpenDialog()
|
|
{
|
|
DialogService.Instance.Add(
|
|
new DialogFrame(
|
|
"Main dialog",
|
|
"Main dialog"
|
|
+ string.Join(
|
|
Environment.NewLine,
|
|
Enumerable.Repeat(Environment.OSVersion, 10)
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|