Display messagebox in dll library

前端 未结 2 526
-上瘾入骨i
-上瘾入骨i 2021-01-24 18:12

I am writing a dll library (for example for checking login details of a user) and I want to pop up a confirmation dialog or a informational dialog in the process, for example

2条回答
  •  无人共我
    2021-01-24 19:03

    You really shouldn't. This does not belong in a library, but should be done in the application that uses this library instead.

    Where a WinForms application might solve it by showing a MessageBox, a web application might perform the request without asking after a successful POST (since a POST usually shows the intent to modify a resource).

    When for example your library is used for logging in, simply throw a AuthenticationException, so the client application (whether it's WinForms, web, or whatever) can catch that and display the appropriate message.


    As for your edit:

    I have a dll for creating database at runtime of an application ...

    Why not expose two methods like IsDatabaseUpToDate() and UpdateDatabase()? Then in the client, you can call the first method. If it returns false, you ask the user (be it with a MessageBox, an HTML form, a JavaScript Alert, a simple Yes button or a blinking tile) whether they want to update the database. If so, you call the UpdateDatabase() method and you're ready to go.

提交回复
热议问题