In hierarchically controlled microgrids, economic dispatch and corresponding real-time control action are inherently performed at different timescales. Owing to the uncertainty in renewables, running economic dispatch in advance may not adequately guarantee the anticipated outcomes. In this paper, distributed optimization algorithms are developed to manage economic dispatch and frequency regulation in microgrids concurrently, leaving the inter-layer coordination across timescales unnecessary. We first formulate a distributed economic dispatch problem that minimizes the overall opportunity cost yielded by renewable energy sources participating in frequency regulation. Then, by considering the dynamical characteristics of inverter-based microgrids, we reconstruct the optimization problem from the perspective of feedback control design utilizing local frequency feedback to perceive and compensate supply-demand imbalance in an online fashion, despite resistance losses. As a result, the proposed algorithms can settle the optimal dispatch and restore the frequency to its nominal value. Under reasonable operational assumptions, the closed-loop stability and asymptotic convergence to the optimal solution are rigorously established. Simulation results demonstrate the effectiveness and tractability of the proposed algorithms.