C#结构中的事件?(Are Events in C# structs?)
所以我有一个EventHandlers字典,但是我发现,当我将字符串中的keyvaluepair添加到事件中时,一切正常。 但是,如果我添加keyvaluepair,然后更新事件处理程序的值,字典不会更新。
public static event EventHandler TestEvent; private static Dictionary<int, EventHandler> EventMapping = new Dictionary<int, EventHandler>(); //TestEvent += GTKWavePipeClient_TestEvent; EventMapping.Add(0, TestEvent); TestEvent += GTKWavePipeClient_TestEvent; //test event is non null now. keyvaluepair in EventMapping has a value of null
So I have a dictionary of EventHandlers, yet I find that when I attach to an event before adding the keyvaluepair to the dictionary, everything works fine. But if I add the keyvaluepair and then update the value of the eventhandler, the dictionary does not update.
public static event EventHandler TestEvent; private static Dictionary<int, EventHandler> EventMapping = new Dictionary<int, EventHandler>(); //TestEvent += GTKWavePipeClient_TestEvent; EventMapping.Add(0, TestEvent); TestEvent += GTKWavePipeClient_TestEvent; //test event is non null now. keyvaluepair in EventMapping has a value of null
原文:https://stackoverflow.com/questions/28861375
最满意答案
使用:
return
:return render :json => fail_any
或者,在
render :json ...
之后使用return
render :json ...
行如:render :json => fail_any return
更新:
render :text => "No Data" and return if some_condition
或者,如果您确定要在此时停止控制器的执行,则只需
render and return
:render :text => "No Data" and return
这可以确保在遇到语句后停止执行,并且在操作代码中不再发生流程,因为它看到了返回。
这篇关于渲染和返回的文章可能会有用。
The problem solved by using threads instead of processes (the default option)
responses = Parallel.map(urls, :in_threads => 3) do |url|
相关问答
更多-
您也可以在控制器中制作开关。 def index @articles = Article.all render "index_without_articles" if @article.nil? end You can also make the switch in the controller. def index @articles = Article.all render "index_without_articles" if @article.nil? end
-
Ruby在函数中使用'return false'时不会停止执行(Ruby not stopping execution when using 'return false' in function)[2022-09-18]
return完成当前方法的执行 - 在您的情况下,如果终止send_response方法并使其返回false。 您想要返回“父”方法: params.each do |key,value| if params_list.include?(key) == false send_response 500, data: 'Invalid parameters used!' and return false end end return finish execution of current me ... -
使用redirect_to后如何停止控制器的执行?(How do I stop controller execution after using redirect_to? (Using Rails))[2022-01-02]
你可能想要使用过滤器。 如果您在控制器check_date称为before_filter ,则其呈现或重定向的事实将阻止控制器调用该操作方法。 那就结束了。 You probably want to use filters. If you call your check_date as a before_filter in the controller, the fact that it rendered or redirected will prevent the controller from ever ... -
Rails - 在控制器中,如何从不同的控制器渲染动作?(Rails - in controller, how to render an action from a different controller?)[2023-08-10]
:action强制rails搜索当前控制器视图文件夹中的模板。 缺少模板评论/ cars / car_profile 你应该写这个 render "cars/car_profile" 见第2.2.3点 如果要从完全不同的控制器渲染模板而不是包含操作代码的控制器,该怎么办? 您也可以使用render执行此操作,render接受要呈现的模板的完整路径(相对于app / views)。 :action forces rails to search for templates within the current ... -
如何在使用渲染后停止控制器执行?(How do I stop controller execution after using render? (Using Ruby on Rails))[2022-07-10]
使用: return : return render :json => fail_any 或者,在render :json ...之后使用return render :json ...行如: render :json => fail_any return 更新: render :text => "No Data" and return if some_condition 或者,如果您确定要在此时停止控制器的执行,则只需render and return : render :text => "No Da ... -
匹配的路线是/users/:user_id/profile/videos(.:format)但你的url是users/profile/videos ,有两个问题。 这不是绝对的(它应该以'/'开头,并且不包含:user_id段)。 你应该使用助手: <%= form_for @video, url: user_profile_videos(user_id: @video.user_id), ... 或类似的东西 The matching route is /users/:user_id/profile/v ...
-
检查您的路线,看看您是否在学校路线中使用create_person方法。 如果是肯定的尝试redirect_to : redirect new_school_person_path 使用new_school_person_path作为该方法的路由。 Check your routes and see if you have the method create_person in schools routes. If positive try redirect_to: redirect new_school ...
-
在post / index方法中添加以下行。 何时在视图中呈现部分html,您的表单会尝试查找post / index方法中找不到的@name对象。 所以我们需要使用新的Name对象初始化@name 。 def index @posts = Post.all @name = Name.new end Add the following line in your post/index method. when to render the partial in your view html , you ...
-
请考虑使用过滤器。 这工作: before_action :method1, only: :start def start .... if some_case render json: {ok: "ok"} end end def method1 ... if some_case render json: {error: "Some error"} return end end 当在过滤器中进行渲染时,它本身不会运行动作,因此不会发生双重渲染。 Consi ...
-
<% seller.fields_for :address do |address_fields| %> 应该 <%= seller.fields_for :address do |address_fields| %> 注意<%后面的“=”符号显示输出我确定你已经意识到这一点,但在版本2.xx之后使用erb标签中的=符号是一个重大变化 <% seller.fields_for :address do |address_fields| %> Should be <%= seller.fields_for ...