开发者

Should I provide Sync or Async methods for developers in my IMDB API library?

I'm going to make a DLL Library that'll alow developers to search and access IMDB movie pages.

How should I handle the freezing开发者_开发知识库 in the GUI, should I use async methods, or should I allow a dev to manually create a thread for using our DLL?


This is entirely up to you.

That being said, I think providing an asynchronous and a synchronous API will make your library act more like the framework libraries, which will give your users the best chance of using it correctly.

For example, WebClient provides DownloadFile and DownloadFileAsync. I would, personally, mimic this behavior in my API. If you implement your library asynchronously, it's very easy to wrap this in a synchronous API.


This is a judgement call on your end. Consider, however:

  1. The user can always use a BackgroundWorker to avoid blocking, if you only expose in a synchronous way.

  2. If you feel that you can provide some intermediary data during the action (like progress percentage) then an asynchronous version may be useful.


I would avoid asynchronous calls within a library like this.

What if the user of the library doesn't care about blocking? What if it's a command-line script that should block?

The threading of an application is a major design decision, avoid making for them.

I would first implement the blocking, synchronous calls and perhaps later, add asynchronous methods to make the library easier to use for thread-shy programmers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜