KEMBAR78
Implement WindowsFormsApplicationBase.IsSingleInstance by cston · Pull Request #3200 · dotnet/winforms · GitHub
Skip to content

Conversation

@cston
Copy link
Contributor

@cston cston commented May 4, 2020

Fixes #2056
Fixes #3131

Proposed changes

Implement support for WindowsFormsApplicationBase single-instance behavior.

Customer Impact

Allows applications using the VisualBasic application model to opt-in to single-instance behavior.

Regression?

Not implemented when porting Microsoft.VisualBasic to .NET Core previously.

Risk

Medium risk when opted-in; low risk otherwise.

Test methodology

Unit tests.

Microsoft Reviewers: Open in CodeFlow

@ghost ghost assigned cston May 4, 2020
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the current Framework behavior. 2 files are considered the same if they only vary by last 2 version fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For projects coming from Framework the developer through VS creates the base value and VB runtime adds 2 additional version strings. If a project is still in Framework and runs on top of Core this behavior will change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Entry.ManifestModule.ModuleVersionId.ToString() will make the Debug and Release version of the same source app different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logged #3296.


In reply to: 419828791 [](ancestors = 419828791)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if this were overridable so developers can select am appropriate algorithm with this being the default.

Copy link
Contributor

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 👍

@cston cston force-pushed the SingleInstance branch from e6440a7 to fdd6101 Compare May 13, 2020 18:09
@cston cston force-pushed the SingleInstance branch from fdd6101 to 8d99319 Compare May 15, 2020 18:48
@cston cston marked this pull request as ready for review May 15, 2020 22:33
@cston cston requested a review from a team as a code owner May 15, 2020 22:33
@cston
Copy link
Contributor Author

cston commented May 15, 2020

cc @KathleenDollard

If nRead = 0 Then
Exit While
End If
stream.Write(buffer, 0, nRead)
Copy link
Member

@jaredpar jaredpar May 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider WriteAsync here since this is already an Async method. #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stream here is a MemoryStream rather than the NamedPipeServerStream.


In reply to: 426088068 [](ancestors = 426088068)

@codecov
Copy link

codecov bot commented May 16, 2020

Codecov Report

Merging #3200 into master will increase coverage by 29.77013%.
The diff coverage is n/a.

@@                 Coverage Diff                  @@
##              master       #3200          +/-   ##
====================================================
+ Coverage   33.28961%   63.05974%   +29.77012%     
====================================================
  Files            883        1310         +427     
  Lines         253893      466288      +212395     
  Branches       36741       39798        +3057     
====================================================
+ Hits           84520      294040      +209520     
- Misses        164586      166853        +2267     
- Partials        4787        5395         +608     
Flag Coverage Δ
#Debug 63.05974% <ø> (+29.77012%) ⬆️
#production 33.31482% <ø> (+0.02520%) ⬆️
#test 98.61626% <ø> (?)

jaredpar
jaredpar previously approved these changes May 26, 2020
If bytesRead = 0 Then
Exit While
End If
stream.Write(buffer, 0, bytesRead)
Copy link
Member

@jaredpar jaredpar May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stream.Write(buffer, 0, bytesRead)
Await stream.WriteAsync(buffer, 0, bytesRead).ConfigureAwait(false)
``` #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream in this case is a MemoryStream so Write() should be equivalent to WriteAsync().


In reply to: 430663031 [](ancestors = 430663031)

}
}

// Should be able to test internal methods with [InternalsVisibleTo] rather than reflection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're actually moving in the opposite direction - prefer reduce "internal" API surface (if it is only used for tests) and use reflection instead.
#3225

TestHelpers.EndProcess(process0, timeout: 1000);
TestHelpers.EndProcess(process1, timeout: 1000);
Assert.True(process0.HasExited);
Assert.True(process1.HasExited);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test that process1 exited on his own accord before trying to close it?

@RussKie
Copy link
Contributor

RussKie commented May 26, 2020

@msftbot merge if @jaredpar approves

@ghost ghost added the :octocat: automerge label May 26, 2020
@dotnet dotnet deleted a comment May 26, 2020
@ghost ghost merged commit 7ccf509 into dotnet:master May 27, 2020
@cston cston deleted the SingleInstance branch May 27, 2020 20:12
@RussKie RussKie added this to the 5.0 Preview6 milestone May 27, 2020
@RussKie
Copy link
Contributor

RussKie commented May 27, 2020

Thank you @cston @jaredpar

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support creating "single instance" applications Support WindowsFormsApplicationBase.IsSingleInstance

4 participants