Skip to content

Commit

Permalink
fix race condition in clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
goswinr committed Dec 11, 2021
1 parent a3db999 commit 4b24154
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
17 changes: 9 additions & 8 deletions AvalonLog.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net472;net50-windows</TargetFrameworks>
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<LangVersion>preview</LangVersion>

Expand All @@ -17,12 +17,13 @@
<Product>AvalonLog</Product>
<PackageId>AvalonLog</PackageId>

<Version>0.4.0</Version>
<AssemblyVersion>0.4.0</AssemblyVersion>
<FileVersion>0.4.0</FileVersion>
<Version>0.5.0</Version>
<AssemblyVersion>0.5.0</AssemblyVersion>
<FileVersion>0.5.0</FileVersion>
<PackageReleaseNotes>
- Update to AvalonEditB 1.2.0
- Rename GetTextWriterIf to GetConditionalTextWriter
- Update to AvalonEditB 1.3.0
- target net6.0 and net472
- fix typos in docstring
</PackageReleaseNotes>

<Authors>GoswinR</Authors>
Expand Down Expand Up @@ -52,10 +53,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AvalonEditB" Version="1.2.0" />
<PackageReference Include="AvalonEditB" Version="1.3.0" />
<!-- <Reference Include="AvalonEditB" HintPath="../AvalonEditB/AvalonEditB/bin/Release/net472/AvalonEditB.dll" /> -->

<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<!-- https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets -->
</ItemGroup>

Expand Down
20 changes: 12 additions & 8 deletions Doc/READMEnuget.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

![logo](https://raw.githubusercontent.com/goswinr/AvalonLog/main/Doc/logo400.png)

Avalonlog is a fast and thread-save WPF text log viewer for colored text. Including F# printf formating . Based on [AvalonEditB](https://github.com/goswinr/AvalonEditB). Works on .NET Framework 4.7.2 and .NET 5.0
AvalonLog is a fast and thread-save WPF text log viewer for colored text. Including F# printf formatting . Based on [AvalonEditB](https://github.com/goswinr/AvalonEditB). Works on .NET Framework 4.7.2 and .NET 5.0

### Usage

Expand All @@ -28,7 +28,7 @@ let red = log.printfColor 255 0 0 // without newline
let blue = log.printfnColor 0 0 255 // with newline
let green = log.printfnColor 0 155 0 // with newline
// print to log using F# printf formating
// print to log using F# printf formatting
red "Hello, "
blue "World!"
red "The answer"
Expand All @@ -48,19 +48,23 @@ public void AppendWithBrush(SolidColorBrush br, string s)
and similar functions on the `AvalonLog` instance.
### Documentation

See extracted API at [fuget.org](https://www.fuget.org/packages/AvalonLog/0.4.0/lib/net472/AvalonLog.dll/AvalonLog)
See extracted API at [fuget.org](https://www.fuget.org/packages/AvalonLog/0.5.0/lib/net472/AvalonLog.dll/AvalonLog)

### Licence
### License

MIT

Logo by [LovePik](https://lovepik.com/image-401268798/crystal-parrot-side-cartoon.html)

### Changelog

`0.3.1`
- Update Xml Docstrings
`0.5.0`
- Update to AvalonEditB `1.3.0`
- target net6.0 and net472
- fix typos in docstring

`0.4.0`
- Update to AvalonEditB `1.2.0`
- Rename `GetTextWriterIf` to `GetConditionalTextWriter`
- Rename `GetTextWriterIf` to `GetConditionalTextWriter`

`0.3.1`
- Update Xml Docstrings
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

![logo](https://raw.githubusercontent.com/goswinr/AvalonLog/main/Doc/logo400.png)

Avalonlog is a fast and threadsave WPF text log viewer for colored text. Including F# printf formating . Based on [AvalonEditB](https://github.com/goswinr/AvalonEditB). Works on .NET Framework 4.7.2 and .NET 5.0
AvalonLog is a fast and thread-save WPF text log viewer for colored text. Including F# printf formatting . Based on [AvalonEditB](https://github.com/goswinr/AvalonEditB). Works on .NET Framework 4.7.2 and .NET 5.0

### Usage

Expand All @@ -31,7 +31,7 @@ let red = log.printfColor 255 0 0 // without newline
let blue = log.printfnColor 0 0 255 // with newline
let green = log.printfnColor 0 155 0 // with newline
// print to log using F# printf formating
// print to log using F# printf formatting
red "Hello, "
blue "World!"
red "The answer"
Expand All @@ -51,7 +51,7 @@ public void AppendWithBrush(SolidColorBrush br, string s)
and similar functions on the `AvalonLog` instance.
### Documentation

See extracted API at [fuget.org](https://www.fuget.org/packages/AvalonLog/0.4.0/lib/net472/AvalonLog.dll/AvalonLog)
See extracted API at [fuget.org](https://www.fuget.org/packages/AvalonLog/0.5.0/lib/net472/AvalonLog.dll/AvalonLog)

### Download

Expand All @@ -61,7 +61,7 @@ AvalonLog is available as [NuGet package](https://www.nuget.org/packages/AvalonL

Just run `dotnet build`

### Licence
### License

MIT

Expand Down
8 changes: 4 additions & 4 deletions Src/AvalonLog.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AvalonLog
namespace AvalonLog

open AvalonLog.Util
open AvalonLog.Brush
Expand Down Expand Up @@ -307,16 +307,16 @@ type AvalonLog () =
docLength <- 0
prevMsgBrush <- null
stillLessThanMaxChars <- true
printCallsCounter := 0L
offsetColors.Clear()
offsetColors.Add {off = -1 ; brush=null} //TODO use -1 instead? // null check done in this.ColorizeLine(line:AvalonEdit.Document.DocumentLine) ..
printCallsCounter := 0L
)

// log.Dispatcher.Invoke needed.
// If this would be done via async{ and do! Async.SwitchToContext a subsequent call via Dispatcher.Invoke ( like print to log) would still come before.
// It starts faster than async with SwitchToContext
log.Dispatcher.Invoke( fun () ->
log.Clear()
offsetColors.Clear() // this should be done after log.clear() to avoid race condition where log tries to redraw but offsetColors is already empty
offsetColors.Add {off = -1 ; brush=null} // null check done in this.ColorizeLine(line:AvalonEdit.Document.DocumentLine) ..
//log.SelectionLength <- 0
//log.SelectionStart <- 0
defaultBrush <- (log.Foreground.Clone() :?> SolidColorBrush |> Brush.freeze) // TODO or remember custom brush ?
Expand Down
2 changes: 1 addition & 1 deletion Src/TextColor.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AvalonLog
namespace AvalonLog

open AvalonLog.Util
open System
Expand Down

0 comments on commit 4b24154

Please sign in to comment.