The stock market has been on the rise lately, with the S&P 500 up more than 16% over the past two months.

Some investors are feeling conflicted about this recent surge, however. While many are hopeful that the worst is behind us and the market will continue to improve, some experts are warning that this rally is only temporary and stock prices may have further to fall.

In reality, nobody knows exactly what the future holds for the market, which can be unnerving. Is now really the right time to invest, then? Or are you better off waiting to see what happens? Here's what you need to know.

Why consider holding off on investing?

In most cases, there's no harm in continuing to invest even if the market takes a turn for the worse. But there are certain situations where you may be better off waiting.

For example, if you don't have an emergency fund with at least three to six months' worth of savings, it may be wise to focus on that goal before you invest in the stock market.

As a general rule of thumb, try to avoid investing any cash you might need in the foreseeable future. Market downturns are one of the worst times to withdraw your money, because stock prices are lower and you'll end up selling your investments at a discount.

If you invest all your spare cash and stock prices plummet, you may have no choice but to tap your investments if you need that money down the road. In that case, you may be better off building a solid safety net now and waiting a little while to invest.

The case for continuing to invest

While it can be daunting to invest when the future is uncertain, right now can be a smart time to buy. In fact, if you can afford it, there's not necessarily a wrong time to invest -- regardless of what the market is doing.

Building wealth in the stock market takes years, if not decades. That means that what happens in the market during the coming days, weeks, or even months might not make a significant difference over the long run. Even if the market crashes tomorrow, it will still most likely see positive average returns over the next 10, 20, or 30 years.

Chart showing overall rise in the S&P 500 since 2010, with recent fall and rebound.

^SPX data by YCharts

Also, with dollar-cost averaging, investing consistently (even during market downturns) can actually save you money over time. Dollar-cost averaging involves investing at regular intervals throughout the year. Rather than investing a large sum of money at once, for example, you invest smaller amounts each month or quarter.

Sometimes, you'll end up investing when stock prices are at their highest. Other times, you'll invest when the market is in a slump and prices are lower. But over time, those highs and lows will average out, and you'll actually spend less than if you'd only invested when the market was thriving.

This approach takes the guesswork out of when to buy, and it can make investing far easier. As long as you plan to keep your money in the market for at least several years, it doesn't necessarily matter when you invest. The future may be uncertain, but if you can afford it, buying now can be a smart move.