public async Task<IReadOnlyList<Coincidence>> ParseAsync(string text, List<string> patternList)
{
var matches = new ConcurrentBag<Coincidence>();
var patterns = new ConcurrentBag<string>(patternList);
int taskCount = Environment.ProcessorCount;
var tasks = new Task[taskCount];
for (int i = 0; i < tasks.Length; i++)
{
tasks[i] = Task.Factory.StartNew(() =>
{
string pattern;
while (!patterns.IsEmpty)
{
if (patterns.TryTake(out pattern))
{
Coincidence coincidence = Find(pattern, text);
if (coincidence != null)
{
matches.Add(coincidence);
}
}
}
});
}
await Task.WhenAll(tasks);
return matches.ToArray();
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
<Window
x:Class="Notification.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Notification.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Notification"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Grid>
<Button
Width="100"
Height="36"
Margin="8,0,0,10"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Click="OnButtonClick"
Content="Button" />
<controls:NotificationControl
x:Name="_notification"
HorizontalAlignment="Center"
VerticalAlignment="Bottom">
<TextBlock
FontSize="32"
Text="NotificationControl content!" />
</controls:NotificationControl>
</Grid>
</Window>
<Application x:Class="Notification.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Notification"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
В идеале - я просто создаю объект надписи и он автоматически запускает свою анимацию и по её окончании удаляется.
1: Как двигать объект?
<Rectangle Width="80" Height="45" Stroke="Blue" Fill="Red">
<Rectangle.RenderTransform>
<TranslateTransform X="10" Y="50" />
</Rectangle.RenderTransform>
</Rectangle>
Вроде можно это сделать с помощью Margin